powershellでよく使うコマンドに関しての紹介をします。
【1. ファイル操作系】
・Get-ChildItem
概要:指定したディレクトリ内のファイルやフォルダを一覧表示します。
使用例:Get-ChildItem -Path "C:\Example\Path"
・Copy-Item
概要: ファイルやフォルダをコピーします。
使用例:Copy-Item -Path "C:\Source\file.txt" -Destination "C:\Destination\file.txt"
・Remove-Item
説明: ファイルやフォルダを削除します。
使用例:Remove-Item -Path "C:\Example\file.txt"
【2. テキスト操作系】
・Get-Content
説明: ファイルの内容を取得します。
使用例:Get-Content -Path "C:\Example\file.txt"
・Set-Content
説明: ファイルに内容を書き込みます。
使用例:Set-Content -Path "C:\Example\file.txt" -Value "New content"
【3. システム情報の取得など】
・Get-Process
説明: 実行中のプロセスを一覧表示します。
・Get-Service
説明: サービスの状態を取得します。
【4. ループと条件分岐など】
・ForEach-Object
説明: 各オブジェクトに対してアクションを実行します。
使用例:Get-ChildItem -Path "C:\Example\Path" | ForEach-Object { $_.Name }
・If-Else
説明: 条件に基づいて異なるアクションを実行します。
使用例:
$value = 10
if ($value -gt 5) {
Write-Output "Value is greater than 5"
} else {
Write-Output "Value is 5 or less"
}
参考URL
Windows パワーシェル(PowerShell)の基本操作を学ぶ│知識と情報のお宝WEBサイト (oldnote.net)
【PowerShell】よく使うコマンド一覧!基礎コマンドの使い方を紹介 - テックパンプ (tellingbook.com)
Microsoft.PowerShell.Management Module - PowerShell | Microsoft Learn