我需要告诉我,我是在短时间内安装Powershell的编程,并且有一些基本问题我暂时无法处理。使用XML填充Powershell中的变量
所以我想要做的是预先输入数据到一个XML文件来使用这些数据并将$ var填充到powershell中,然后使用这些var来更改Active Directory属性。对于更改AD属性我很好,但通过调用XML文件来填充我的var的自动化过程根本就不起作用。我想我没有使用得到的方法,这就是为什么我要求帮助。
这是我的XML文件(其中我只有两个网站声明)
<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>
我想用一个变量名称$目的地为“-match” location.site.city。如果$目的地配城,然后填写了var
$Newcity = location.site.city
$NewStreet = location.site.street
$NewState = location.site.state
等,等
这里的脚本我做的一部分,但我不能得到我想要的结果。
$var1 = ""
$Street = ""
$Destination = "Alma"
[xml]$SiteAttribute = Get-Content SitesAttributes.xml
foreach($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
}
}
然后我会用这些变种改变我的AD属性与其他PowerShell命令
##Normal AD module come with W2k8
Import-Module ActiveDirectory
Set-ADUser $username -server $dc -StreetAddress $NewStreet -City $NewCity -State $NewState -PostalCode $NewZip -OfficePhone $NewPhone -Country $NewCountry
但我都尝试zhcon失败,原因我想接着我的我的foreach语句如果声明是不够的为我想要做的过程。有什么建议?
感谢 约翰
是的,这样更好。我会说大拇指@ C.B。谢谢,我不是很远,但因为我不习惯使用XML文件,所以很容易犯错。 – lotirthos227