PowerShell / 메모
Created 2023-08-15
Last Modified 2026-05-23
업그레이드
- 버전 확인
PS C:\> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.19041.3031
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.3031
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
- 최신 버전 확인
PS C:\> winget search Microsoft.PowerShell 이름 장치 ID 버전 원본 --------------------------------------------------------------- PowerShell Microsoft.PowerShell 7.3.6.0 winget PowerShell Preview Microsoft.PowerShell.Preview 7.4.0.5 winget
- 최신 버전 설치
winget install --id Microsoft.Powershell --source winget
도움말
- 도움말 업데이트
Update-Help
- Get-Help 명령어의 도움말
Get-Help -Name Get-Help
명령어 찾기
- 모든 명령어 출력
Get-Command
- 동사가 Get이면서 명사가 H로 시작하는 것 출력
Get-Command -Verb Get -Noun H*
보안 오류로 스크립트가 실행되지 않을 때
ExecutionPolicy의 값을 확인하고, Restricted라면 RemoteSigned로 변경해봅니다.
- 값 확인
Get-ExecutionPolicy
- 값 변경
Set-ExecutionPolicy RemoteSigned
주석
한 줄 주석
#을 추가한다. # 이후가 주석 처리된다.
여러 줄 주석
<#과 #>로 감싼다.
예제
현재 디렉토리 안의 폴더, 파일 크기 출력
Get-ChildItem | ForEach-Object {
if ($_.PSIsContainer) {
$size = (Get-ChildItem $_.FullName -Recurse -File -ErrorAction SilentlyContinue |
Measure-Object Length -Sum).Sum
[PSCustomObject]@{
Name = $_.Name
Type = "Folder"
SizeMB = "{0:N2}" -f ($size / 1MB)
}
}
else {
[PSCustomObject]@{
Name = $_.Name
Type = "File"
SizeMB = "{0:N2}" -f ($_.Length / 1MB)
}
}
} | Format-Table -AutoSize
Get-ChildItem | ForEach-Object {
if ($_.PSIsContainer) {
$size = (Get-ChildItem $_.FullName -Recurse -File -EA SilentlyContinue |
Measure-Object Length -Sum).Sum
}
else {
$size = $_.Length
}
[PSCustomObject]@{
Name = $_.Name
SizeBytes = $size
}
} | Sort-Object SizeBytes -Descending | ForEach-Object {
$size = $_.SizeBytes
$display =
if ($size -ge 1GB) {
"{0:N2} GB" -f ($size / 1GB)
}
elseif ($size -ge 1MB) {
"{0:N2} MB" -f ($size / 1MB)
}
elseif ($size -ge 1KB) {
"{0:N2} KB" -f ($size / 1KB)
}
else {
"$size Bytes"
}
[PSCustomObject]@{
Name = $_.Name
Size = $display
}
} | Format-Table -AutoSize
기타








