need to get adusers and replace the null value to a empty space so the xml file will be defined, now when its runned if user properties are empty it will not add value it will be like properties are defined in a array
# Base XML
$xml = [xml]@"
<?xml version="1.0" encoding="UTF-8"?>
<users>
</users>
"@
$ad=get-aduser miljkovicd -properties name| select name| Out-Null
# Template for creating nodes.
$userTemplate = @"
<user>
<sn>{0}</sn>
<givenName>{1}</givenName>
<mailNickname>{2}</mailNickname>
<mail>{3}</mail>
<telephoneNumber>{4}</telephoneNumber>
<company>{5}</company>
<title>{6}</title>
<employeeID>{7}</employeeID>
<mobile>{8} </mobile>
<facsimileTelephoneNumber>{9} </facsimileTelephoneNumber>
<extensionAttribute11>{10}
{11}"@`
#$base = 'ou=my users,dc=mydomain,dc=com'
#$date = (Get-Date).AddDays(-1) $property=@
"sn","givenName","mailNickname","mail","telephoneNumber","company","title","employeeID","mobile","extensionAttribute11","extensionAttribute12" )
$Users= Get-ADUser mil -Properties $property |ForEach{
# Create and append a child for each user
$child = $xml.ImportNode(([xml]($userTemplate -f $users.cn,$_.givenname,$_.mailNickname,$_.mail,$_.telephoneNumber,$_.company,$_.cn,$_.employeeID,$_.mobile,$_.facsimileTelephoneNumber,$_.extensionAttribute11,$clean)).DocumentElement,$true)
$xml.documentelement.AppendChild($child) | Out-Null
# $child = $xml.ImportNode(([xml]($userTemplate2 -f $_.title,$_.employeeID,$_.mobile,$_.mail,$_.extensionAttribute11,$_.extensionAttribute12)).DocumentElement,$true)
#$xml.documentelement.AppendChild($child) | Out-Null
}
Should use your own path and a variable here.
$xml.Save("c:\temp\te4.xml")
Aucun commentaire:
Enregistrer un commentaire