Last active
January 15, 2017 06:01
-
-
Save VertigoRay/7b73da2cace3d49a2cf2 to your computer and use it in GitHub Desktop.
The `$MyInvocation.ScriptLineNumber` variable is not the Current Line Number. It’s the Line number from where the function that you’re in was called. Actual line numbers can be caught for an error if you catch them. Used in this comment: http://goo.gl/7oeSEL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function a { | |
param( | |
[string]$UninstallString = 'thing' | |
) | |
$MyInvocation | |
Write-Host -Fore Cyan "$($here.File) $($MyInvocation.MyCommand):$($MyInvocation.ScriptLineNumber)" | |
b | |
try { | |
Throw('Thing!!!!') | |
} catch { | |
Write-Host -Fore Magenta ("{0} {1}:{2}: ErRaWr!! $_" -f @($here.File, $MyInvocation.MyCommand, $_.InvocationInfo.ScriptLineNumber)) | |
} | |
} | |
function b { | |
$MyInvocation | |
Write-Host -Fore Cyan "$($here.File) $($MyInvocation.MyCommand):$($MyInvocation.ScriptLineNumber)" | |
} | |
# Buiding a $this style variable, but $this is an auto variable. | |
$here = @{ | |
'File'='Test' | |
} | |
Write-Host -Fore Cyan "$($here.File) $($MyInvocation.MyCommand):$($MyInvocation.ScriptLineNumber)" | |
a | |
Write-Host -Fore Cyan "$($here.File) $($MyInvocation.MyCommand):$($MyInvocation.ScriptLineNumber)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output