powershell - Proxyaddresses added to the multivalued attribute not appearing on seperate lines -


i using following script create spreadsheet of users , proxyaddress values (matching string) record prior removing them, in case of emergency want able put values back.

the script works if there single entry per user, issue seen when user has more 1 entry. problem when attempt revert original values, when viewed through attribute editor proxyaddresses appearing on 1 line instead of separate line each proxy address. not sure if fault on collection script, or script using set values. collect values running following:

$entry = "*test.com" $users = get-content "testusers.txt" $date = get-date $mydata = @() $domain = [system.environment]::userdomainname  $attribute = "proxyaddresses" $report = "{0}_{1}_{2:hhmm_dd-mm-yyyy}.txt" -f $attribute,$domain,$date $px = $users | get-aduser -properties proxyaddresses -server $domain  foreach ($user in $px){ if ($user.proxyaddresses -like $entry){     $name = $user.samaccountname     $proxyaddresses = $user.proxyaddresses -like $entry     $mydata += new-object psobject -property @{         samaccountname = $name         proxyaddresses = $proxyaddresses     }   } } $mydata | select samaccountname,@{ l = "proxyaddresses"; e = {$_.proxyaddresses } }| export-csv "$pwd\$report" -notypeinformation -append 

to return values original state running following:

$csv = import-csv "proxyaddresses_domain_1201_05-04-2017.csv" $domain = [system.environment]::userdomainname  $attribute = "proxyaddresses" foreach ($line in $csv){ $user = $line.samaccountname $proxyaddresses = $line.proxyaddresses get-aduser $user -server $domain -properties $attribute | set-aduser -add  @{$attribute = $proxyaddresses} -server $domain } 

i have tried various things such in collection script

$proxyaddresses = $line.proxyaddresses -join "," 

i have tried same tactic in script used set values instead of creating new line removes space between entries on same line when viewed through ad attribute editor.

i have tried change

$proxyaddresses = $user.proxyaddresses -like $entry  

to following did not solve problem

$proxyaddresses = ([microsoft.activedirectory.management.adpropertyvaluecollection]$user.proxyaddresses -like $entry 

help!!!

when exporting data, change select statement

select samaccountname,@{ l = "proxyaddresses"; e = {$_.proxyaddresses } }

to

select samaccountname,@{name="proxyaddresses";expression={$_.proxyaddresses -join "*"}}

which convert adpropertyvaluecollection * separated string. if exporting csv, don't want use comma join separator mess csv. i've used * in example, exchange uses colons , semi colons already.

then when re-import it, make sure convert * seperated string string array, , use -replace instead of -add

set-aduser -replace @{$attribute = $proxyaddresses.split("*")} -server $domain


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -