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

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -