Hi
I’ve cobbled together a number of code snippets to create a script that copies an ADUser (ADUC > Right Click User > Copy) including the stuff AD misses out (Streetname etc). I’m quite happy with this so far and am trying to prettyify it.
I use ISE by default, but it may also be run by others from the console. I am wanting to put a ‘Press any key…’ at the end of the script to say that it’s done and have used:
$x= $Host.UI.RawUI.ReadKey("NoEcho, IncludeKeyDown")
as suggested in Don Jones on this site.
However this throws an error in ISE (hate - red text). I’ve since found some code that uses $psISE to check if it’s in ISE and then run some code.
If (!$psISE) {
The "ReadKey" functionality is not supported in Windows PowerShell ISE.
$Shell = New-Object -ComObject "WScript.Shell"
$Button = $Shell.Popup("Click OK to continue.", 0, "Script Paused", 0)
Return
}
However, this throws errors in the console.
Down to my question: is there a way that I can tell if the code is being run from the console or ISE?
Thanks
Tony