Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
Posts: 15
Joined: Thu Aug 01, 2013 6:14 pm
Location: Melbourne, Australia


Post by Nillth » Thu Jun 08, 2017 4:10 pm

Just a minor update to the Built-in Snippit I thought I would share.

When developing code/debugging and running just a section, the built in Get-ScriptDirectory throws an error as the the values it is looking for do not exist, this will return the current working directory that the PowerShell Session Console is in.

Code: Select all

#Sample function that provides the location of the script
function Get-ScriptDirectory
Get-ScriptDirectory returns the proper location of the script.


Returns the correct path within a packaged executable.
param ()
if ($hostinvocation -ne $null)
Split-Path $hostinvocation.MyCommand.path
elseif ($script:MyInvocation.MyCommand.Path -ne $null)
Split-Path $script:MyInvocation.MyCommand.Path