0

ベンダー ソフトウェアのアップグレードを展開するために使用するスクリプトがあります。このスクリプトは、xml を利用して、さまざまな展開パスをマップします。PowerShell 3 への強制アップグレード後、今週、これが機能しなくなったことに気付きました。以下は、この問題を説明するための小さなデモ スクリプトです。

$xml = [xml] (Get-Content (Get-Item (".\FooBar.xml")))
$foobar = $xml.Stuff.FooBars.Foobar 

$ScriptBlock = {        
    $foobar = $args[0]

    write-host "Inside the job..."
    write-host ("Foobar     : "+$foobar)
    write-host ("Foobar.Foo : "+$foobar.Foo)
    write-host ("Args       : "+$args)
}

write-host "Outside the job..."
write-host ("Foobar: "+$foobar)
write-host ("Foobar.Foo : "+$foobar.Foo)

Start-Job -ScriptBlock $ScriptBlock -Args $foobar | Out-Null        
While (Get-Job -State "Running") { Start-Sleep 2 }               

write-host ("Jobs Completed.")    
Get-Job | Receive-Job          
Remove-Job *      

私のxml:

<?xml version="1.0"?>
<Stuff xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <FooBars>
    <FooBar>
      <Foo>ThisIsAFoo</Foo>
      <Bar>ThisIsABar</Bar>
    </FooBar>
  </FooBars> 
</Stuff>

v2 での出力:

Outside the job...
Foobar: System.Xml.XmlElement
Foobar.Foo : ThisIsAFoo
Jobs Completed.
Inside the job...
Foobar     : System.Collections.ArrayList System.Collections.ArrayList
Foobar.Foo : ThisIsAFoo
Args       : System.Collections.ArrayList

v3 での出力:

Outside the job...
Foobar: System.Xml.XmlElement
Foobar.Foo : ThisIsAFoo
Jobs Completed.
Inside the job...
Foobar     : System.Collections.ArrayList System.Collections.ArrayList
Foobar.Foo : 
Args       : System.Collections.ArrayList

したがって、v2 では Foobar.Foo を判別できますが、v3 では判別できないことに注意してください。これを引き起こす原因と最善の回避策はありますか? スコープの問題?私のより大きなスクリプトでは、XmlElement が追加の関数に渡されるため、それを別のオブジェクトに変換したり、プロパティに分割して個別に送信したりすることは避けたいと思います。

4

1 に答える 1