Use XML to fill variable in Powershell

MasterJJJJ

New Member
I need to tell that iI'm programming in Powershell for quiet short time and there is some basic that I do not handle well for the moment. So what I'm trying to do is to pre-enter data into a XML file to use those data and populate $var into powershell then use those var to change Active Directory Attribute. For the change AD attribute i'm good, but the automation process by calling XML file to fill my var is simply not working at all. I think i'm not using the got method and that's why i'm asking for help.Here's my XML file (where I have only two Site declared)\[code\]<Location> <Site> <City>Alma</City> <Street>333 Pont Champlain Street</Street> <POBox></POBox> <State>Ontario</State> <Zip>G1Q 1Q9</Zip> <Country>CA</Country> <OfficePhone>+1 555-555-2211</OfficePhone> </Site> <Site> <City>Dolbeau</City> <Street>2525 Avenue du Pinpont</Street> <POBox></POBox> <State>Quebec</State> <Zip>G2Q 2Q9</Zip> <Country>CA</Country> <OfficePhone>+1 555-555-3000</OfficePhone> </Site></Location>\[/code\]I want to use a var name $Destination to "-match" location.site.city. If the $destination match city, then fill the var \[code\]$Newcity = location.site.city$NewStreet = location.site.street$NewState = location.site.state\[/code\]etc, etcHere's the part of script I did but I can't get the result that I want. \[code\]$var1 = ""$Street = ""$Destination = "Alma"[xml]$SiteAttribute = Get-Content SitesAttributes.xmlforeach( $City in $SiteAttribute.location.Site){ $var1 = $site.city If ($var1 -match $Destination){ $NewStreet = $Site.Street $NewCity = $Site.city $NewPoBox = $site.POBox $NewState = $site.State $Newzip = $Site.zip $NewCountry = $Site.country $NewPhone = $Site.OfficePhone } }\[/code\]Then I would use those var to change my AD attribute with an other Powershell command\[code\]##Normal AD module come with W2k8Import-Module ActiveDirectorySet-ADUser $username -server $dc -StreetAddress $NewStreet -City $NewCity -State $NewState -PostalCode $NewZip -OfficePhone $NewPhone -Country $NewCountry\[/code\]But all my try faild, cause I think my Foreach statement followed by my If statement is not adequate for the process I want to do. Any advice ?ThanksJohn
 
Back
Top