powershell - How to print return value of function -
so have simple function
return current script location:
function get-currentdir { $myinvocation.mycommand.path }
and want print this, try powershell ise after function declaration:
write-host $(get-currentdir) write-host (get-currentdir) write-host get-currentdir
and output:
write-host $(get-currentdir) --> write-host $(get-currentdir) write-host (get-currentdir) --> write-host (get-currentdir) write-host get-currentdir --> write-host get-currentdir
what doing wrong ?
ok, need variable script scope, so:
function get-currentdir { $script:myinvocation.mycommand.path }
also won't work interactively. want read more about_scopes in powershell.
Comments
Post a Comment