Posts Tagged ‘Dot Source’

A Dot Source Reminder for Advanced Functions

Saturday, February 25th, 2017

One of the problems with writing advanced functions is that new PowerShell users think that they don’t do anything.  Frankly, I couldn’t figure out a way to get a notification to work, so I reached out to the sponsor for the Charlotte PowerShell User Group, Microsoft PFE Brian Wilhite. Brian sent me some code  which I incorporated into the following snippet:

If you expect to have the end user save the function with code calling it at the bottom of the script, try this version which won’t prompt if there is additional text at the bottom:

Put either bit of code at the bottom of any advanced function. If the script is run inside the ISE, you will get something like this:

If you run it inside the PowerShell console you will see:

If you use the shell menu option to Run with PowerShell, it adds a pause so the script does not close.  Note that the colors are not rendered properly in the example text  — the first line has green text, subsequent lines are default.