I have a function foo on my local Machine. (In my profile, but calling c:\scripts\foo.ps1 would be also OK!) How do i load this on ServerA and ServerB so i can execute the function in the next statement?
This is what i tried with no success..
$serverlist =
"192.168.20.1",
"192.168.20.12"
foreach ($item in $serverlist) {
New-PSSession -ComputerName "$item" -Credential $cred -Name ($item + "_session")
Invoke-Command -ComputerName $item -Credential $cred -filepath scripts:\foo.ps1
Invoke-Command -ComputerName $item -Credential $cred -scriptblock {foo}
}