I've got the following script:
param(
[string[]]$servers
)
function Write-Info($message) {
}
function Introspect($server) {
Write-Info "about to do something on server"
// other powershell stuff that works
}
Foreach ($server in $servers) {
Invoke-Command -ComputerName $server -ScriptBlock ${function:Introspect} -ArgumentList $server -credential 'MyUser'
}
That I'm trying to invoke on a remote server like so (from powershell):
.\myscript.ps1 server1,server2,server3
The script is executing, but the issue is I get an error relating to the Write-Info
function like so:
The term 'Write-Info' is not recognised as the name of a cmdlet, function, script file, or operable program
The Introspect
function works fine if I embed the function inside but I guess it relates to the function not being on the remote server.
How can I solve this please?