View call_powershell_from_bow.sh
#
# 良い例が思いつかなかったのでとりあえずgrepしてみる
#
# -Commandパラメータはスクリプトブロックとしては認識されず、文字列として指定する必要があるっぽい。
#
/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -Command '&{ Get-NetFirewallRule }' | grep Name
View PowerShellMemoOnWin10-1703.md

バージョン情報

PS C:\> $PSVersionTable | sort Name

Name                           Value
----                           -----
PSVersion                      5.1.15063.0
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
View Slice-ArraySample.ps1
# 配列をn個ずつに分割
$Array = 1..100
$n = 13
# 単純にスライスする
for ($i = 0; $i -lt $Array.Length; $i+=$n) {
Write-Host $Array[$i..($i+($n-1))]
}
# ForEach-Objectで頑張る
View Disable-VBoxServiceTimeSync.ps1
# ゲスト側で実行してVirtualBox Guest Additions Serviceの設定を変える。
sc.exe config VBoxService binPath= "C:\Windows\System32\VBoxService.exe --disable-timesync"
Restart-Service -Name VBoxService
View Invoke-Test.ps1
Write-Host "Hello $env:COMPUTERNAME" -ForegroundColor Green
View Get-WindowsFeatureFromTemplate.ps1
$TemplatePath = ".\展開の構成テンプレート.xml"
(Import-Clixml -LiteralPath $TemplatePath).GetEnumerator() | % { $_.CimClass.CimClassQualifiers["DisplayName"].Value } | Get-WindowsFeature
View Get-EdgeDockerVersion.ps1
$dockers = (Invoke-RestMethod -Uri 'https://go.microsoft.com/fwlink/?LinkID=825636&clcid=0x409')
$dockers.versions.$($dockers.channels.edge.version)
View install-powershell-appimage.sh
# Tested on CentOS 7.3
# AppImage requires FUSE
sudo yum install -y epel-release
sudo yum -y install --enablerepo=epel fuse-sshfs
# Install PowerShell AppImage
curl -OL https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-alpha.17/PowerShell-x86_64.AppImage
chmod a+x ./PowerShell-x86_64.AppImage
./PowerShell-x86_64.AppImage
View powershell-class-fields.ps1
#
# PowerShell Class "Field" is converted to Property.
#
class PSClass
{
[string]$Field1 = "F1"
}
Write-Output "Get Field information from [PSClass].GetMembers() -> returns Property"
[PSClass].GetMembers() | ? { $_.Name -eq "Field1" } | select Membertype | Out-String
View Convert-SyukujitsuCSV.ps1
# 面倒なので適当
"http://www8.cao.go.jp/chosei/shukujitsu/syukujitsu.csv" `
| % { (curl $_).Content } `
| % { [Text.Encoding]::GetEncoding(932).GetString([Text.Encoding]::GetEncoding("ISO-8859-1").GetBytes($_)) -split "`r`n" } `
| ? { $_ -ne "" -and $_ -notlike "*,,,,," } `
| select -Skip 2 `
| % { $cs = $_ -split ','; for( $i=0; $i -lt $cs.Length; $i+=2 ){ [PSCustomObject]@{Date=[Datetime]$cs[$i+1];Name=$cs[$i]} } } `
| sort Date `
| ConvertTo-Csv -NoTypeInformation