Updating value for multiple users

Posted on 2014-03-10
Last Modified: 2014-03-11

There is an attribute called " gidNumber" on our AD accounts that is used for Unix access.
I need to update the value for multiple accounts but testing on just one account it does not
find the attribute .

If I do:
Set-ADUser "Test123" -gidNumber "10"

I receive the error below .

Set-ADUser : A parameter cannot be found that matches parameter name 'gidNumber'.
At line:1 char:23
+ Set-ADUser "Test123" -gidNumber "10"
+                       ~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Set-ADUser], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.SetADUser

When I run the command below it does show me the current gidNumber value .
Get-ADUser "Test123" -Properties * | select gid*
Question by:MilesLogan
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 40

Expert Comment

ID: 39918501
Just because there is an attribute called "gidNumber" doesn't mean there is a parameter for Set-Aduser with the same name.  When Set-ADUser doesn't include a specific parameter to adjust an attribute, you can use the -add, -replace, -remove, and -clear parameters to modify those attributes based on their LDAP display names.
So you could use
Set-ADUser "Test123" -replace @{gidNumber="10"}

Open in new window


Author Comment

ID: 39918530
Thanks footech for the explanation ..  I ran below and it worked .

gc users.txt | Set-ADUser -Replace @{gidNumber="1000"}

can you help me output a file of the accounts that where modified ? or I can ask it in another question if needed .
LVL 40

Expert Comment

ID: 39918574
I'm not sure I understand your requirements.
Your users.txt file should already contain a list of the users that are modified.
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.


Author Comment

ID: 39918606
actually .. I just saw something ..

Not all accounts in users.txt will need to have the gidNumber changed to 1000 ..only the accounts that have a number in that field already... if there is no value , then nothing needs to be done .

Can you help me with a script for that ?
LVL 40

Accepted Solution

footech earned 500 total points
ID: 39919082
Try the following.
gc users.txt | % { Get-ADUser $_ -properties gidNumber } | ? {$_.gidNumber} | Set-ADUser -Replace @{gidNumber="1000"} -PassThru | % { Write-Output "$($_.samaccountname) was updated" } | Out-File updatedusers.txt

Open in new window


Author Closing Comment

ID: 39922092
Hi footech:  this worked ! thanks !
LVL 40

Expert Comment

ID: 39922156
You're welcome.

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here's a look at newsworthy articles and community happenings during the last month.
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question