PowerShellチートシート
サーバー・ネットワーク管理向けPowerShellコマンドのチートシート
94 件のコマンド
Get-ChildItemファイルとフォルダの一覧を表示
Get-ChildItem -Path C:\ -Recurse -Filter *.logCopy-Itemファイルやフォルダをコピー
Copy-Item -Path .\src -Destination .\backup -RecurseMove-Itemファイルやフォルダを移動・名前変更
Move-Item -Path .\old.txt -Destination .\new.txtRemove-Itemファイルやフォルダを削除
Remove-Item -Path .\temp -Recurse -ForceNew-Item新しいファイルやフォルダを作成
New-Item -Path .\logs -ItemType DirectoryGet-Contentファイルの内容を読み取り
Get-Content -Path .\app.log -Tail 50Set-Contentファイルに内容を書き込み(上書き)
Set-Content -Path .\config.txt -Value 'setting=true'Add-Contentファイルに内容を追記
Add-Content -Path .\log.txt -Value 'New entry'Test-Pathパスの存在を確認
Test-Path -Path C:\Windows\System32Get-ItemPropertyファイルやレジストリのプロパティを取得
Get-ItemProperty -Path .\file.txt | Select-Object LastWriteTimeCompress-ArchiveファイルをZIPに圧縮
Compress-Archive -Path .\logs -DestinationPath .\logs.zipExpand-ArchiveZIPファイルを展開
Expand-Archive -Path .\logs.zip -DestinationPath .\logsTest-NetConnectionネットワーク接続とポートをテスト
Test-NetConnection -ComputerName google.com -Port 443Get-NetIPAddressIPアドレス設定を表示
Get-NetIPAddress -AddressFamily IPv4Get-NetAdapterネットワークアダプター一覧を表示
Get-NetAdapter | Where-Object Status -eq 'Up'Resolve-DnsNameDNS名前解決を実行
Resolve-DnsName -Name example.com -Type MXGet-NetTCPConnectionTCP接続の一覧を表示
Get-NetTCPConnection -State EstablishedGet-NetRouteルーティングテーブルを表示
Get-NetRoute -AddressFamily IPv4New-NetIPAddressIPアドレスを設定
New-NetIPAddress -InterfaceIndex 12 -IPAddress 192.168.1.100 -PrefixLength 24Set-DnsClientServerAddressDNSサーバーアドレスを設定
Set-DnsClientServerAddress -InterfaceIndex 12 -ServerAddresses 8.8.8.8,8.8.4.4Test-ConnectionICMP pingを送信
Test-Connection -ComputerName server01 -Count 4Invoke-WebRequestHTTPリクエストを送信
Invoke-WebRequest -Uri https://api.example.com -Method GETInvoke-RestMethodREST APIにリクエストを送信
Invoke-RestMethod -Uri https://api.example.com/data -Method POST -Body $jsonGet-Process実行中のプロセス一覧を表示
Get-Process | Sort-Object CPU -Descending | Select-Object -First 10Stop-Processプロセスを停止
Stop-Process -Name notepad -ForceStart-Process新しいプロセスを開始
Start-Process -FilePath notepad.exe -ArgumentList .\file.txtGet-Serviceサービスの一覧と状態を表示
Get-Service | Where-Object Status -eq 'Running'Start-Serviceサービスを開始
Start-Service -Name W3SVCStop-Serviceサービスを停止
Stop-Service -Name W3SVC -ForceRestart-Serviceサービスを再起動
Restart-Service -Name SpoolerSet-Serviceサービスのプロパティを変更
Set-Service -Name W3SVC -StartupType AutomaticGet-Jobバックグラウンドジョブの一覧を表示
Get-Job | Where-Object State -eq 'Running'Start-Jobバックグラウンドジョブを開始
Start-Job -ScriptBlock { Get-EventLog -LogName System -Newest 100 }Get-ComputerInfoコンピューターの詳細情報を取得
Get-ComputerInfo | Select-Object OsName, OsVersion, CsTotalPhysicalMemoryGet-EventLogイベントログを取得
Get-EventLog -LogName System -Newest 20 -EntryType ErrorGet-WinEventWindowsイベントログを取得
Get-WinEvent -LogName Application -MaxEvents 50Get-HotFixインストール済み更新プログラムを表示
Get-HotFix | Sort-Object InstalledOn -DescendingGet-WmiObjectWMI情報を取得
Get-WmiObject -Class Win32_OperatingSystem | Select-Object Caption, VersionGet-CimInstanceCIMインスタンスを取得(WMI後継)
Get-CimInstance -ClassName Win32_Processor | Select-Object Name, NumberOfCoresGet-Counterパフォーマンスカウンターを取得
Get-Counter '\Processor(_Total)\% Processor Time' -SampleInterval 2 -MaxSamples 5Get-Date現在の日時を取得・書式設定
Get-Date -Format 'yyyy-MM-dd HH:mm:ss'Get-Uptimeシステムの稼働時間を表示
Get-UptimeGet-WindowsFeatureWindowsの機能と役割を表示
Get-WindowsFeature | Where-Object InstalledInstall-WindowsFeatureWindowsの機能をインストール
Install-WindowsFeature -Name Web-Server -IncludeManagementToolsGet-LocalUserローカルユーザーの一覧を表示
Get-LocalUser | Where-Object EnabledNew-LocalUserローカルユーザーを作成
New-LocalUser -Name 'newuser' -Password (ConvertTo-SecureString 'P@ss' -AsPlainText -Force)Remove-LocalUserローカルユーザーを削除
Remove-LocalUser -Name 'olduser'Set-LocalUserローカルユーザーのプロパティを変更
Set-LocalUser -Name 'user1' -PasswordNeverExpires $trueGet-LocalGroupローカルグループの一覧を表示
Get-LocalGroupAdd-LocalGroupMemberローカルグループにメンバーを追加
Add-LocalGroupMember -Group 'Administrators' -Member 'user1'Remove-LocalGroupMemberローカルグループからメンバーを削除
Remove-LocalGroupMember -Group 'Administrators' -Member 'user1'Get-LocalGroupMemberローカルグループのメンバーを表示
Get-LocalGroupMember -Group 'Administrators'Get-Volumeボリューム情報を表示
Get-Volume | Where-Object DriveLetterGet-Diskディスクの一覧を表示
Get-Disk | Select-Object Number, FriendlyName, Size, PartitionStyleGet-Partitionパーティション情報を表示
Get-Partition -DiskNumber 0Get-PSDrivePowerShellドライブの一覧を表示
Get-PSDrive -PSProvider FileSystemNew-Partition新しいパーティションを作成
New-Partition -DiskNumber 1 -UseMaximumSize -AssignDriveLetterFormat-Volumeボリュームをフォーマット
Format-Volume -DriveLetter D -FileSystem NTFS -Confirm:$falseInitialize-Diskディスクを初期化
Initialize-Disk -Number 1 -PartitionStyle GPTGet-PhysicalDisk物理ディスク情報を取得
Get-PhysicalDisk | Select-Object FriendlyName, MediaType, Size, HealthStatusGet-NetFirewallRuleファイアウォールルールの一覧を表示
Get-NetFirewallRule -Enabled True -Direction InboundNew-NetFirewallRule新しいファイアウォールルールを作成
New-NetFirewallRule -DisplayName 'Allow HTTP' -Direction Inbound -Protocol TCP -LocalPort 80 -Action AllowRemove-NetFirewallRuleファイアウォールルールを削除
Remove-NetFirewallRule -DisplayName 'Allow HTTP'Set-NetFirewallRuleファイアウォールルールを変更
Set-NetFirewallRule -DisplayName 'Allow HTTP' -Enabled FalseEnable-NetFirewallRuleファイアウォールルールを有効化
Enable-NetFirewallRule -DisplayName 'Allow HTTP'Disable-NetFirewallRuleファイアウォールルールを無効化
Disable-NetFirewallRule -DisplayName 'Allow HTTP'Get-NetFirewallProfileファイアウォールプロファイルの設定を表示
Get-NetFirewallProfile | Select-Object Name, EnabledSet-NetFirewallProfileファイアウォールプロファイルを設定
Set-NetFirewallProfile -Profile Domain -Enabled TrueEnter-PSSessionリモートコンピューターに対話的に接続
Enter-PSSession -ComputerName server01 -Credential (Get-Credential)Exit-PSSessionリモートセッションを終了
Exit-PSSessionInvoke-Commandリモートコンピューターでコマンドを実行
Invoke-Command -ComputerName server01,server02 -ScriptBlock { Get-Service W3SVC }New-PSSession永続的なリモートセッションを作成
New-PSSession -ComputerName server01 -Credential $credGet-PSSessionリモートセッションの一覧を表示
Get-PSSessionRemove-PSSessionリモートセッションを削除
Get-PSSession | Remove-PSSessionEnable-PSRemotingPowerShellリモーティングを有効化
Enable-PSRemoting -ForceCopy-Item -ToSessionリモートセッションにファイルをコピー
Copy-Item -Path .\script.ps1 -Destination C:\Scripts -ToSession $sessionGet-IISSiteIISサイトの一覧を表示
Get-IISSiteStart-IISSiteIISサイトを開始
Start-IISSite -Name 'Default Web Site'Stop-IISSiteIISサイトを停止
Stop-IISSite -Name 'Default Web Site'New-IISSite新しいIISサイトを作成
New-IISSite -Name 'MySite' -PhysicalPath C:\inetpub\mysite -BindingInformation '*:8080:'Get-IISAppPoolIISアプリケーションプールの一覧を表示
Get-IISAppPool | Select-Object Name, StateImport-Module WebAdministrationIIS管理モジュールをインポート
Import-Module WebAdministrationGet-WebBindingWebサイトのバインド情報を表示
Get-WebBinding -Name 'Default Web Site'New-WebBindingWebサイトにバインドを追加
New-WebBinding -Name 'MySite' -Protocol https -Port 443 -HostHeader mysite.example.comGet-ADUserActive Directoryユーザーを検索
Get-ADUser -Filter * -SearchBase 'OU=Users,DC=example,DC=com' -Properties EmailAddressNew-ADUserADユーザーを作成
New-ADUser -Name 'John Smith' -SamAccountName jsmith -Enabled $true -AccountPassword (ConvertTo-SecureString 'P@ss' -AsPlainText -Force)Set-ADUserADユーザーのプロパティを変更
Set-ADUser -Identity jsmith -Department 'IT' -Title 'Engineer'Remove-ADUserADユーザーを削除
Remove-ADUser -Identity jsmith -Confirm:$falseGet-ADComputerADコンピューターオブジェクトを検索
Get-ADComputer -Filter * -Properties OperatingSystem | Select-Object Name, OperatingSystemGet-ADGroupADグループを検索
Get-ADGroup -Filter 'Name -like "IT*"'Add-ADGroupMemberADグループにメンバーを追加
Add-ADGroupMember -Identity 'IT-Team' -Members jsmithGet-ADGroupMemberADグループのメンバーを表示
Get-ADGroupMember -Identity 'Domain Admins' -RecursiveGet-ADOrganizationalUnitADの組織単位(OU)を表示
Get-ADOrganizationalUnit -Filter * | Select-Object Name, DistinguishedNameUnlock-ADAccountロックされたADアカウントを解除
Unlock-ADAccount -Identity jsmith