Problem with Invoke-Command and functions


i have written following code

cls  function getbar() {  	$bar = "bar"  	$bar  }    function getfoo() {  	$foo = "foo"  	$bar = getbar  	$foo  	$bar  }    $cred = get-credential "domain\user"  $result = invoke-command -credential $cred -computername localhost -scriptblock ${function:getfoo}  write-host $result[0]  write-host $result[1]

gives error

term 'getbar' not recognized name of cmdlet, function, script file, or operable program. check spelling of name, or if path included, verify pat
h correct , try again.
    + categoryinfo          : objectnotfound: (getbar:string) [], commandnotfoundexception
    + fullyqualifiederrorid : commandnotfoundexception

why not able find function?


val it: unit=()

it's same if doing in local session.  once get-bar defined in a session, other fuctions or script run in session can use - no, need define once.

[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

server manager error: ADAM.events.xml could not be enumerated.

Cannot access Anywhere Access using domain name?

WMI Failure: Unable to update Local Resource Group