프로그래밍/powershell
[powershell] 파워쉘 프로세스 개수 체크하기
IT맥구리나스
2023. 10. 6. 13:26
파워쉘을 통해 프로세스 갯수를 체크하여 참 거짓을 나타낼 수 있다.
아래 명령어와 같다.
powershell if((Get-Process "notepad" -ErrorAction SilentlyContinue).Count -eq 3 -and (Get-Process "game" -ErrorAction SilentlyContinue).Count -eq 2) { Write-Host "true" } else { Write-Host "false" }
코드 설명
if 문으로 notpad프로세스가 3개 떠있으면서(and연산) game프로세스가 2개 떠있으면 참 아니면 거짓
프로세스 조회 : Get-Process "프로세스명"
-ErrorAction SilentlyContinue : 에러가 발생해도 프롬프트에 안남기겠단 옵션
-and : and 연산자
파워쉘 프로세스 체크
배치 프로세스 체크
파워쉘 and 연산
반응형