powershell 사용법
update-help
cls
Get-ExecutionPolicy -> 스크립트를 실행할 수 있는지 확인
Set-ExecutionPolicy RemoteSigned -> 실행가능하게 변경
Enable-PsRemoting -> 원격실행 활성화
Windows Powershell ISE : Integrated Scripting Environment
-> 명령어 실행, 스크립트 작성, 실행
명령어 구조
Verb-Noun -Parameter <Argument>
프로세스 정보 보기
Get-Process
Get-Process -Name winlogon
도움말 보기
Get-Help Get-Process examples
Help Get-Process
Get-Process -?
명령어 리스트 보기
get-command
get-command -type cmdlet
get-help get-service
Format 출력형식
Format-wide : 기본형식
Format-List
Format-Table
Format-Custom
Get-Process | Format-Wide -Column 4 ==> 4개의 컬럼으로 보여줌. 디폴트는 2개의 컬럼
Get-Process | Format-List
Get-Process | Format-Table
Get-Process -Name powershell | Format-Table
DisplayName 속성에 xbox가 들어간 서비스만 필터링
Get-Service | Where-Object { $_.DisplayName -match "xbox" }
==> PowerShell에서 $_는 파이프라인(Pipeline)에서 현재 처리 중인 개별 항목을 의미하는 특수 자동 변수입니다.
파일 목록에서 .log 파일만 찾기
Get-ChildItem | Where-Object { $_.Name -like "*.log" }
프로세스 중 CPU 사용률 10% 이상인 것
Get-Process | Where-Object { $_.CPU -gt 10 }
서비스 중지된 것만 보기
Get-Service | Where-Object { $_.Status -eq 'Stopped' }
이름에 'sql'이 포함된 서비스 찾기
Get-Service | Where-Object { $_.DisplayName -match 'sql' }
사용자 목록에서 길이가 5자 이상인 이름만 출력
'John', 'Anna', 'Michael', 'Eve' | Where-Object { $_.Length -ge 5 }
$_ 현재 항목 (Current Object in the Pipeline)
$_.속성 그 항목의 특정 속성
$_.메서드() 그 항목의 메서드 실행
탭키를 누르면 자동 완성기능이 있다.
8443 프트 확인하기.
netstat -ano | findstr LISTENING
netstat -ano | findstr 8443
'IT > Shell Script' 카테고리의 다른 글
주기적으로 뭔가?? 를 실행하는 스크립트... (0) | 2023.12.28 |
---|---|
ftp 에서 파일을 가져오는 스크립트 (0) | 2023.12.28 |
댓글