XML to powershell array -


i want load xml content array within powershell script. why dows not work? :(

my xml:

<settings>     <services>        <sv>service1</sv>        <sv>service2</sv>     </services> </settings> 

my powershell script. seems work, i'm not sure

[xml]$xml = get-content "d:\config.xml" [array]$service_arr = $xml.settings.services.sv 

but want display it, "cannot index null array."

$service_arr[0] 

i don't want have variable different generic name each service. want able address services array[0]...array[1] etc.

you don't have cast $xml.settings.services.sv explicit [array], can iterate on using example foreach loop:

foreach ($service in $xml.settings.services.sv) {     write-host $service } 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -