2012-12-18 4 views
0

벤더 소프트웨어 업그레이드를 배포하는 데 사용되는 스크립트가 있습니다. 이 스크립트는 xml을 활용하여 다른 배포 경로를 매핑합니다. 나는이 문제를 설명하기 위해 아래 3. PowerShell을 위해 강제 업그레이드 후 작은 데모 스크립트를 이번 주입니다 작동이 중지주의 :Powershell 시작 작업 arg에 v3으로 업그레이드 한 후에 데이터가 없음

$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 :

: v2의

<?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> 

출력 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 : ThisIsAFoo 
Args  : System.Collections.ArrayList 

출력 :

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가 추가 함수에 전달되므로 다른 개체로 변환하거나 해당 속성으로 분리하여 개별적으로 보내는 것은 피하고 싶습니다.

답변

0

방금 ​​같은 문제가 발생했습니다. 아직 정확한 원인을 찾지 못했지만 해결 방법으로 플래그 -PSVersion 2.0을 시작 - 작업 줄에 추가 할 수 있습니다.

관련 문제