本記事では、PowerShellの基本コマンドとナビゲーション操作について説明します。

基本コマンド一覧

コマンド説明使用例
Get-Location現在のディレクトリ(作業フォルダ)を表示する。Get-Location
Set-Locationディレクトリを移動する。(cdと同じ)Set-Location C:\work
Get-ChildItemファイルやフォルダの一覧を表示する。(dirやlsと同じ)Get-ChildItem
New-Itemファイルやフォルダを作成する。New-Item test.txt -ItemType File
Remove-Itemファイルやフォルダを削除する。Remove-Item test.txt
Copy-Itemファイルやフォルダをコピーする。Copy-Item test.txt backup.txt
Move-Itemファイルやフォルダを移動・名前変更する。Move-Item old.txt new.txt
Rename-Item名前を変更する。Rename-Item old.txt new.txt
Get-Contentテキストファイルの内容を表示する。Get-Content log.txt
Set-Contentファイルに内容を書き込む。Set-Content test.txt “Hello”
Add-Contentファイルに追記する。Add-Content test.txt “World”
Clear-Host画面をクリア(clsと同じ)Clear-Host
Get-Helpコマンドのヘルプを表示する。Get-Help Get-Process
Get-Command使用可能なコマンドを検索する。Get-Command *service*
Get-Process実行中のプロセスを表示する。Get-Process
Stop-Processプロセスを停止する。Stop-Process -Name notepad
Get-Serviceサービスの状態を表示する。Get-Service
Start-Serviceサービスを開始する。Start-Service Spooler
Stop-Serviceサービスを停止する。Stop-Service Spooler


ナビゲーション操作

現在位置を確認する

Get-Location


ディレクトリを移動する

Set-Location C:\work

または、

cd C:\work


一つ上の階層へ移動する

Set-Location ..


ホームディレクトリへ移動する

Set-Location ~



以上、PowerShellの基本コマンドとナビゲーション操作について解説しました。