I am running into a little issue, I have generated runbooks using powershell. One of them connects to Vmware using a build up similar to this
The code
TempFunction{
connects to vmware using VMuser1 credentials
runs code etc...
All is well
return $TempVariable
}
$TempVariable = Invoke-Command -ScriptBlock ${function:TempFunction} -ComputerName localhost
This all works fine.
The problem is that when I introduce a global array named InfoArray that stores information along the way and at the end wish to write it to a different server using other credentials it fails stating "Invoke-Command: The Using variable is not supported in the script function or filter"
Here is my introduced code:
#Append gathered log information to log
$strScriptUser = "domain\FileUser"
$strPass = "Password01"
$PSS = ConvertTo-SecureString $strPass -AsPlainText -Force
$cred = new-object system.management.automation.PSCredential $strScriptUser, $PSS
Start-Job -ScriptBlock { Add-Content $using:Logfile $using:InfoArray } -Credential $cred
return $TempVariable
}
Any ideas as to how I could solve this issue? The following does not work
Start-Job -ScriptBlock { Add-Content $Logfile $InfoArray } -Credential $cred
Regards Akr