PowerShell メモ

2021-06-01

よくつかうエイリアス

Clear-Hostclear, cls
Compare-Objectcompare, diff
Copy-Itemcopy, cp, cpi
ForEach-Object%, foreach
Get-ChildItemdir, gci, ls
Get-Contentcat, gc, type
Get-Historyghy, h, history
Get-Locationgl, pwd
Get-Processgps, ps
helpman
Invoke-WebRequestcurl, iwr, wget
mkdirmd
Move-Itemmi, move, mv
New-Itemni
New-PSDrivemount, ndr
Remove-Itemdel, erase, rd, ri, rm, rmdir
Rename-Itemren, rni
Select-Objectselect
Set-Locationcd, chdir, sl
Set-Variableset, sv
Start-Processsaps, start
Stop-Processkill, spps
Where-Object?, where
Write-Outputecho, write

このコマンドの代わりは?

whichGet-Command
timemeasure-command
grepselect-string
touch a.txt ( b.txt c.txt)new-item a.txt (, b.txt, c.txt)

変数への代入

$greet="hello"

$files=Get-ChildItem

オブジェクトのプロパティの確認

$files | get-member


TypeName: System.IO.FileInfo

Name                      MemberType     Definition
----                      ----------     ----------
LinkType                  CodeProperty   System.String LinkType{get=GetLinkType;}
...

比較演算子

about_Comparison_Operators

-eq==
-ne!=
-gt>
-ge>=
-lt<
-le<=
-like文字列がワイルドカードパターンと一致
-notlike同 一致しない
-match文字列が正規表現パターンと一致
-notmatch同 一致しない

絞り込み

 $files |? {$_.name -like "*src*"}