powershell - piping get-aduser output to set-aduser within a foreach loop -
i trying list of users telephone attrib null , update atrrib phone number, far here have:
$allen=gc "c:\0nix\03scripts\tmp\jkirb\allen.txt" $phonenumber = "972-xxx-xxx" foreach ($user in $allen) { $nophone = get-aduser $user -pr *| {$_.telephonenumber -eq $null} | select samaccountname |ft -hidetableheaders set-aduser -identity "$nophone" -replace @{telephonenumber="$phonenumber"} }
which erroring this: set-aduser : cannot find object identity: 'microsoft.powershell.commands.internal.format.formatstartdata microsoft.powershell.commands.internal.format.groupstartdata microsoft.powershell.commands.internal.format.formatentrydata microsoft.powershell.commands.internal.format.groupenddata microsoft.powershell.commands.internal.format.formatenddata' under: 'dc=bhcs,dc=pvt'. @ line:7 char:1 + set-aduser -identity "$nophone" -replace @{telephonenumber="$phonenumber"} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : objectnotfound: (microsoft.power...t.formatenddata:aduser) [set-aduser], adidentitynotfoundexception + fullyqualifiederrorid : cannot find object identity: 'microsoft.powershell.commands.internal.format.formatstartdata microsoft.powershell.commands.internal.format.groupstartdata mic rosoft.powershell.commands.internal.format.formatentrydata microsoft.powershell.commands.internal.format.groupenddata microsoft.powershell.commands.internal.format.formatenddata' under: 'dc=
bhcs,dc=pvt'.,microsoft.activedirectory.management.commands.setaduser
you adding custom formatting object when use of format-* cmdlets (format-table in case) , ruins object future pipeline use.
try instead:
$allen=gc "c:\0nix\03scripts\tmp\jkirb\allen.txt" $phonenumber = "972-xxx-xxx" foreach ($user in $allen) { $nophone = get-aduser $user -pr *| {$_.telephonenumber -eq $null} set-aduser -identity "$nophone" -replace @{telephonenumber="$phonenumber"} }
Comments
Post a Comment