$LogFile = ‘C:\temp\Test_Purish.log’ $userscsv = Import-Csv c:\temp\user.csv; foreach ($user in $userscsv) { echo $user.ACTION; echo '--------------------------'; $userMap=@{ #"ACTION"="$($user.ACTION)"; "NTDomainUID"="$($user.NTDomainUID)"; "DisplayName"="$($user.DisplayName)"; "KnownasGivenName"="$($user.KnownasGivenName)"; "KnownasSn"="$($user.KnownasSn)"; "Knownasinitial"="$($user.Knownasinitial)"; "DivisionName"="$($user.DivisionName)"; "DivisionCode"="$($user.DivisionCode)"; "C"="$($user.C)"; "PostalAddress"="$($user.PostalAddress)"; "city"="$($user.city)"; "St"="$($user.St)"; "ZipCode"="$($user.ZipCode)"; "TelephoneNumber"="$($user.TelephoneNumber)"; "EfaxNumber"="$($user.EfaxNumber)"; "Mobile"="$($user.Mobile)"; "Pager"="$($user.Pager)"; "DepartmentCode"="$($user.DepartmentCode)"; "DepartmentName"="$($user.DepartmentName)"; "Title"="$($user.Title)"; "physicaldeliveryofficename"="$($user.physicaldeliveryofficename)"; "personalAssistantDN"="$($user.personalAssistantDN)"; "CDStatus"="$($user.CDStatus)"; "utcManagerDN"="$($user.utcManagerDN)"; "othertelephone"="$($user.othertelephone)"; "exportcontrol"="$($user.exportcontrol)"; "utcLegacyExchangeDN"="$($user.utcLegacyExchangeDN)"; "alternatedivisioncode"="$($user.alternatedivisioncode)"; } foreach($eachKey in $userMap.GetEnumerator()) { <#echo $eachKey.key echo $eachKey.value#> if ($user.ACTION -eq "CREATE") { #Create new mail contact } elseif($user.ACTION -eq "MODIFY") { if($eachKey.value.StartsWith("ADD")) { $attrKey = $eachKey.key $attrVal = $eachKey.value.Substring(4) #Set mail contact #Set-MailContact -Identity $Alias -$eachKey.key '$eachKey.value'; } elseif($eachKey.value.StartsWith("REPLACE")) { $uniqueKey=$user.NTDomainUID $attrKey = $eachKey.key $attrVal = $eachKey.value.Substring(8) echo $attrKey; #Set mail contact Set-MailContact -Identity $uniqueKey -$attrKey $attrVal; } if($eachKey.value.StartsWith("REMOVE")) { $attrVal = $eachKey.value.Substring(7) #Set mail contact } Write-Output "$attrVal" | Out-File $LogFile -append } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)