리눅스 터미널은 자주 접하지만, PowerShell은 사용할 일이 많지 않아 기록해둘 필요가 생겼다.
1) get-help Get-Process
2) Help Get-Process
3) Get-Process -?
1) get-command -type Cmdlet // cmdlet 타입의 명령만 볼 수 있음
2) get-help get-service // get-service 명령어의 도움말
3) Get-Module // 사용 가능한 모듈 목록 표시
1) Format-Wide // 기본 형식 출력
1-1) Get-Process | Format-Wide // 2행 출력
1-2) Get-Process | Format-Wide -column 4 // 4행 출력
2) Format-List // 목록 형식 출력
2-1) Get-Process | Format-List
3) Format-Table // 테이블 형식 출력
3-1) Get-Process | Format-Table
4) Format-Custom // *값 설정 필요
get-service | where-object {$_.Displayname -Math "Windows"}
dir
Get-ChildItem
Get-ChildItem // 현재 디텍토리 목록 보기
gci // 상동
gci -force // 숨겨진 파일과 폴더 같이 보기
gci -recurse // 하위 디렉토리까지 보여줌
예시) gci -path "C:\program files" -recurse -include *.exe
copy-item -path C:\f1.txt -Destination C:\a1\ // 파일 복사
copy-item -path C:\b1 -Destination C:\a1\ // 폴더 복사
cd 또는 Set-Location: 디렉터리를 변경합니다.
dir 또는 Get-ChildItem: 디렉터리 내용을 나열합니다.
mkdir 또는 New-Item: 디렉터리를 만듭니다.
rm 또는 Remove-Item: 파일 또는 디렉터리를 삭제합니다.
move-item -path C:\f1.txt -Destination C:\b1\
move-item -path C:\f1.txt -Destination C:\b1\
remove-item -path C:\a1\
rm -path C:\a1\
new-item -path "c:\a1" -itemtype Directory
new-item -path "C:\f2.txt" -itemtype file
set-content C:\f2.txt "Hello World" // f2.txt에 내용 수정
set-content C:\f2.txt "Hello PowerShell" // f2.txt에 내용 수정 (위 내용 삭제됨. OverWrite)
Get-ChildItem | out-file c:dirlist.txt // dirlist.txt 에 Get-ChildItem 내용이 담김.
Add-Content C:\f2.txt "bye" // f2.txt에 내용 추가
Get-Content C:\dirlist.txt // dirlist.txt 내용 읽기
get-service |convertTo-HTML name, displayname, status | set-content c:\svc.html // get-service 내용을 html 파일로 만들기
get-childitem|export-clixml c:\XMLtest.xml // get-childitem 내용을 XMLtest.xml 파일로 내보내기
get-service |Export-Csv c:\svcList.csv // get-service svcList.csv 파일로 내보내기
import-csv C:\svcList.csv // svcList.csv 파일 내용 가져오기
Invoke-Item C:\svcList.csv // svcList.csv (엑셀로) 열기
.\myFile.exe // myFile.exe 스크립트 실행