Skip to content

Instantly share code, notes, and snippets.

@jhochwald
Last active January 23, 2016 14:00
Show Gist options
  • Save jhochwald/528d824f15673545655f to your computer and use it in GitHub Desktop.
Save jhochwald/528d824f15673545655f to your computer and use it in GitHub Desktop.
$MyInvocation vs. Sapien PowerShell Studio
<#
$MyInvocation vs. Sapien PowerShell Studio
Sorry, $MyInvocation is empty if you compile the Script!
This is a Workaround, that checks $host.Name and use
the Sapien Variant $HostInvocation instead.
#>
if ($host.Name -eq 'PrimalScriptHostImplementation') {
$Global:MyRunPath = (Split-Path -Parent $HostInvocation.MyCommand.Path)
$Global:MyScriptName = ($HostInvocation.mycommand.name)
$Global:MyRunName = (([io.fileinfo]$HostInvocation.MyCommand.Definition).BaseName)
} else {
$Global:MyRunPath = (Split-Path -Parent $MyInvocation.MyCommand.Path)
$Global:MyScriptName = ($MyInvocation.mycommand.name)
$Global:MyRunName = (([io.fileinfo]$MyInvocation.MyCommand.Definition).BaseName)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment