pwsh
PowerShell 基礎 早見表
起動
powershell pwsh // PowerShell 7+
ヘルプ
Get-Help cmdlet名 Get-Help Get-ChildItem -Examples Update-Help Get-Command Get-Command -Noun Process Get-Member
ナビゲーション
| 操作 | コマンドレット | エイリアス |
|---|---|---|
| 現在地 | Get-Location | pwd, gl |
| 移動 | Set-Location | cd, sl |
| 一覧 | Get-ChildItem | ls, dir, gci |
| 作成 | New-Item | ni, mkdir |
ファイル操作
| 操作 | コマンドレット | エイリアス |
|---|---|---|
| 内容表示 | Get-Content | cat, type, gc |
| コピー | Copy-Item | cp, copy, cpi |
| 移動 | Move-Item | mv, move, mi |
| 削除 | Remove-Item | rm, del, ri |
| 作成 | New-Item | ni |
プロセス・サービス
Get-Process // gps, ps Stop-Process // kill, spps Get-Service Start-Service Stop-Service
オブジェクト操作
Where-Object // ?, where ForEach-Object // %, foreach Select-Object // select Sort-Object // sort Measure-Object ConvertTo-Csv ConvertTo-Html Export-Csv Import-Csv
変数・基本構文
$var = "値"
$var | Get-Member
if ($cond) { } else { }
foreach ($item in $list) { }
while ($cond) { }
よく使うパラメータ
- Path / -Recurse
- Filter / -Include
- Verbose
- WhatIf
- Confirm
実行ポリシー
Get-ExecutionPolicy Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
バージョン確認
$PSVersionTable pwsh -Version
ヒント
- タブ補完強い
- | でパイプライン
- オブジェクト渡し
- Get-Command *Item で関連コマンド探し
- スクリプト: .ps1 拡張子、#Requires -Version 7
pwsh.txt · 最終更新: by Takuya Nishimoto
