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

php - trouble displaying mysqli database results in correct order -

depending on nth recurrence of job in control M -

sql server - Cannot query correctly (MSSQL - PHP - JSON) -