Invoke-command problem

by wuwu at 2012-08-16 22:52:08

Hello,

I have this script:

cls
$strSvr_Cluster = “ZServer4”
$script_ConfigurationEACluster =
{
Write-Host $InputFile
$InputFile1 = “c:\Temp\EAInstallerInput.xml”
# $InputFile1 = “\zserver100\c$\Temp\EAInstallerInput.xml”

[xml]$xmlinput = (Get-Content $InputFile1)
If ($xmlinput.Configuration.EA_Adapters)
{
ForEach ($Adapter in $xmlinput.Configuration.EA_Adapters.EA_Adapter)
{
$Adaptername = $Adapter.Name
Write-Host $Adaptername
}
}
}

Invoke-Command -ComputerName $strSvr_Cluster <br> -ScriptBlock $script_ConfigurationEACluster
-ErrorAction StopThe problem:



When the variable $InputFile1 = “c:\Temp\EAInstallerInput.xml” then the script works fine and i get the right result:

Result:

Adaptername: MES_EA_EQ1

Adaptername: MES_EA_EQ2


When the variable $InputFile1 = “\ZServer\100\c$\Temp\EAInstallerInput.xml” then the script doesn’t work.

I get this error:

Cannot find path ‘\zmucmossdev100\c$\Temp\EAInstallerInput.xml’ because it does not exist.
At C:\Users\yadwutschehor\AppData\Local\Temp\2\7f5a5aa9-c177-464e-aacb-136f9f9185e3.ps1:line:20 char:1

+ I <<<< nvoke-Command -ComputerName $strSvr_Cluster <br><br>The file exist at Server ZServer100\c$\Temp. I start this xml file over IE at server Zserver4, the invoke-command server<br><br>I hope somebody can help me,<br><br>Horst</blockquote>by wuwu at 2012-08-16 23:56:51<blockquote>This is the solution:<br><br><code>cls<br>$strSvr_Cluster = &quot;ZServer4&quot;<br>$InputFile = &quot;\\zserver100\c$\Temp\EAInstallerInput&#46;xml&quot;<br><br>$script_ConfigurationEACluster = <br> {<br> param(&#91;xml&#93;$xmlinput)<br> If ($xmlinput&#46;Configuration&#46;EA_Adapters)<br> {<br> ForEach ($Adapter in $xmlinput&#46;Configuration&#46;EA_Adapters&#46;EA_Adapter)<br> {<br> $Adaptername = $Adapter&#46;Name<br> Write-Host $Adaptername<br> }<br> }<br> }<br> <br>Invoke-Command -ComputerName $strSvr_Cluster
-ScriptBlock $script_ConfigurationEACluster <br> -ErrorAction Stop
-ArgumentList ([io.file]::ReadAllText("$InputFile"))

by jmiller76 at 2012-08-17 08:01:59
you could also put your
$InputFile = "\zserver100\c$\Temp\EAInstallerInput.xml"
as
$InputFile = ‘\zserver100\c$\Temp\EAInstallerInput.xml’
…with single quotes.
The “$” from the admin share is probably being interpreted.
If you get an error like that make sure that Test-path returns true so that you know there are no typos or escaped value issues.