Feature Request: Debug Capability for PowerShell Connector
Presently debugging a PowerShell connector script requires extensive use of logging.
While the above is still going to be necessary, the ability to attach a PowerShell ISE session to a PowerShell process to allow step-throughs and breakpoints is highly desirable.
Answer
Hey Bob,
Thanks for the suggestion. We'll investigate - there seems to potentially be a way to debug a script but may not involve the ISE.
# The following approach allows you to debug a PowerShell connector or adapter transform in IdB # See the following for background: # - https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/wait-debugger?view=powershell-6 # - https://stackoverflow.com/questions/42731150/how-to-pause-a-powershell-script-until-a-debugger-attaches # Prerequisite: PowerShell v5, IdB 5.*, PS connector or adapter transform # 1. Edit the PowerShell code and set a pause in your PowerShell code - long enough to intercept the process and enter debug mode: # you can use wait-debugger, but for now Matt showed me by using start-sleep instead #Wait-Debugger -Timeout 10 Start-Sleep 30 # 2. Find the process ID Get-Runspace # 3. Attach the ISE Enter-PSHostProcess -Name Unify.Service.Connect # 4. Debug the process Debug-Runspace -Id xx
Additional requirements - you must:
- Run ISE as the UNIFYBroker service account credentials
AND - Run ISE as an Administrator
One way to do this is to log in as the UNIFYBroker service account in order to make the connection. Since the UNIFYBroker user is not normally granted remote login access this will need to be temporarily granted while debugging is taking place.
An alternative way to achieve this is via the following PowerShell (courtesy Matt Davis):
Start-Process powershell -Credential domain\differentUserName -ArgumentList '-noprofile -command &{Start-Process "powershell.exe" -verb runas}'
Further clarifications regarding using the commands listed by Bob above:
- In ISE (to identify the current RunSpace ID): Get-Runspace
- At the start of the the PS transform: Start-Sleep -Sec 30
- In UNIFYBroker: Generate Changes to run the transform
- In ISE: Enter-PSHostProcess -Name Unify.Service.Connect
- In ISE: Get-Runspace
- Ignore the runspace ID from step 1 above, pick the other one instead
- In ISE: Debug-Runspace -Id <ID from step 6>
- No prompt will appear until the the transform's Start-Sleep command completes. Once it does, you can look at $entities and run other commands interactively, and they will be executed in the context of the UNIFYBroker PowerShell transform.
- In ISE (to exit the debugging session): exit
- After exiting the transform you'll need to re-run from step 4 if you want to connect to a subsequent one.
Customer support service by UserEcho