Skip to main content

Posts

How to Tell a Script if it is Running in the Shell or ISE?

Sometimes some code just does not work the same in the console as it does in the ISE.  Here is an example. ISE PS C:\> [CHAR]50000 썐 Shell All that we did was asked to display the character associated with the ASCII code 50000.  As you can see, the ISE can display it, but the Shell cannot.  So what if you need to alter the behavior of your code or just out right exit your code based on if your code is running in the Shell or ISE.  Well, here is a little function that you can add to your code. 1 2 3 4 5 Function Test-ISEHost {     If (( Get-host ) . Name -like "*ISE*" ) { Write-Output $True }     Else { Write-Output $False } }     Since I run a lot of my code from the ISE, I am testing to see my code is using the ISE or not.  This code will return TRUE if running in the ISE and False otherwise.  With this Boolean value, you can make decisions. 1 2 3 4 5 6 7 8 9 1...

Get Help Creating PowerShell Help Files

Updated: May 25, 2015 – The code now includes the filters for PowerShell V5 Common Parameters. One of the tasks of creating a polished and professional looking PowerShell cmdlet or script is to include a help file.  In my humble opinion, the cmdlet Get-Help is the most powerful cmdlet in all of PowerShell.  I’ve been saying that since I discovered it in PowerShell V2 and I still say that in all of my PowerShell and Windows classes.  The reason that it is so powerful is because of the excellent design of the help system and our ability to use it with everything that we create.  So why are so many PowerShell code writers not willing to write a help file for all of their hard work?  When I talk about this in class, it is like I am speaking about a taboo subject.  Most people hate to write “documentation”.  This is part of creating that professional product.  In my PowerShell classes, where we actually do learn to write help files, there are two iss...