My Technical Notes

Wednesday, 16 December 2015

PowerShell: Printing out the line which invoked a script

For debugging/information purposes, we want to know what the line that caused the script to execute. For this we use `$MyInvocation.Line`:


Param([string]$x, [string]$y, [string]$z) 

$MyInvocation.Line

Running this script:


.\script.ps1 -x "Tahir" -y "Ahmed" -z "Hassan"

outputs our command as a string:


.\script.ps1 -x "Tahir" -y "Ahmed" -z "Hassan"

No comments: