PowerShell 명령어(Cmdlet)는 대부분 동사-명사 형식을 사용한다.
명령어 | 별칭(Alias) | 설명 | 예시 |
---|---|---|---|
Get-ChildItem | ls, dir | 현재 위치의 파일·폴더 목록 출력 | Get-ChildItem C:\Users |
Set-Location | cd | 디렉토리 이동 | Set-Location D:\Projects |
Copy-Item | cp | 파일·폴더 복사 | Copy-Item file.txt backup.txt |
Move-Item | mv | 파일·폴더 이동 | Move-Item file.txt D:\Backup |
Remove-Item | rm, del | 파일·폴더 삭제 | Remove-Item test.txt |
New-Item | - | 새 파일·폴더 생성 | New-Item newfile.txt |
명령어 | 설명 | 예시 |
---|---|---|
Get-Process | 현재 실행 중인 프로세스 목록 보기 | Get-Process |
Stop-Process | 특정 프로세스 종료 | Stop-Process -Name notepad |
Get-Service | 서비스 상태 확인 | Get-Service |
Start-Service | 서비스 시작 | Start-Service -Name Spooler |
Stop-Service | 서비스 중지 | Stop-Service -Name Spooler |
명령어 | 설명 | 예시 |
---|---|---|
Select-String | 파일에서 특정 문자열 검색 | Select-String -Path "log.txt" -Pattern "error" |
Where-Object | 조건에 맞는 데이터 필터링 | `Get-Process |
Sort-Object | 결과 정렬 | `Get-ChildItem |
Select-Object | 특정 컬럼만 선택 | `Get-Process |
# 출력
Write-Output "Hello, PowerShell!"
# 변수 선언
$name = "유준상"
$age = 27
Write-Output "이름: $name, 나이: $age"
• 기호로 앞 명령의 결과를 다음 명령으로 전달
# 프로세스 목록에서 메모장만 필터링
Get-Process | Where-Object { $_.ProcessName -like "*note*" }
# 현재 실행 정책 확인
Get-ExecutionPolicy
# 로컬 스크립트 실행 허용
Set-ExecutionPolicy RemoteSigned
PowerShell 스크립트 파일 확장자는 .ps1 이다.