Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Updating value for multiple users

Posted on 2014-03-10
7
Medium Priority
?
250 Views
Last Modified: 2014-03-11
Hi EE

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*
0
Comment
Question by:MilesLogan
  • 4
  • 3
7 Comments
 
LVL 41

Expert Comment

by:footech
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

0
 
LVL 2

Author Comment

by:MilesLogan
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 .
0
 
LVL 41

Expert Comment

by:footech
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.
0
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.

 
LVL 2

Author Comment

by:MilesLogan
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 ?
0
 
LVL 41

Accepted Solution

by:
footech earned 2000 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

0
 
LVL 2

Author Closing Comment

by:MilesLogan
ID: 39922092
Hi footech:  this worked ! thanks !
0
 
LVL 41

Expert Comment

by:footech
ID: 39922156
You're welcome.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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.
In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

772 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