본문 바로가기
PowerShell

파워셸 디버깅

by Ate1es 2022. 11. 20.

중단점 설정과 관리

 

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/set-psbreakpoint?view=powershell-7.3 

 

Set-PSBreakpoint (Microsoft.PowerShell.Utility) - PowerShell

The Set-PSBreakpoint cmdlet sets a breakpoint in a script or in any command run in the current session. You can use Set-PSBreakpoint to set a breakpoint before executing a script or running a command, or during debugging, when stopped at another breakpoint

learn.microsoft.com

Set-PSBreakPoint


아래와 같이 특정 스크립트의 특정 라인에 BP를 걸 수 있음

Set-PSBreakporint -Line 11 -Script .\Test.ps1

Line 이외에도 변수와 명령어에도 BP를 걸 수 있다.

Set-PSBreakpoint -Command {{사용자 지정 함수}}
Set-PSBreakpoint -Variable {{변수}} -script {{실행스크립트}}

위 예시처럼 -Command 옵션, -Variable 옵션을 통해서 BP 설정 가능

  • -Command : 해당 지정 함수나 명령이 실행될때 Break
  • -Variable : 해당 변수가 호출될때나 변경될때 Break

Get-PSBreakPoint


Get-PSBreakPoint 명령어를 통해서 현재 파워셸 세션에서 걸려있는 BP 확인 가능

현재 test1.ps1 스크립트에 11번 라인과 ResultBMI 라는 변수에 BP가 걸려있는 것을 확인함

 

Disable-PSBreakPoint , Enable-PSBreakPoint


여기서 비활성화하고 싶은 BP는 Disable-PSBreakpoint 명령어로 비활성화 가능

아래 명령어를 통해 BP ID 3번 ->> ResultBMI 라는 변수에 걸려있던 BP 비활성화

Disable-PSBreakpoint -Id 3

반대로 활성화는 Enable-PSBreakpoint 해주면됨

 

Remove-PSBreakPoint


BP 삭제는 Remove-PSBreakpoint -Id {{BP id}} 로 삭제 해주면 된다.

Remove-PSBreakpoint -Id 0

 

## 주의 사항 ##

BP는 해당 파워셸 세션 내에서만 유효하므로, 한 파워셸 콘솔에서 설정한 BP가 다른 콘솔에 영항을 끼치지 않는다.

 

 

'PowerShell' 카테고리의 다른 글

파워셸[PowerShell] 기본이 중요하다 1편  (0) 2022.10.23