I would like to get the process ID or handle of the current powershell script when I double click and run a PS1 file from Windows Explorer.
This works:
$hwndPowerShell = Get-Process -Name "PowerShell"
But if I have multiple PowerShell console open, how do I get the handle of the current script?
I know one other way is to use the Win32 API FindWindow to find the latest instance of PowerShell console.