Updating active directory No sign up cam fun
I debated about doing this, but, in the end, because I am using the company name in three different places, I decided it would save some time and not add too much complexity to the script.The two lines of code that create the variable and import the module are shown here. Get-ADUser -Search Base 'ou=testou,dc=iammred,dc=net' -Filter * Then, I use the For Each-Object cmdlet to permit me to create email addresses and home pages.Email Address is mail in ADSI, and Home Page is w WWHome Page in ADSI.The first thing I do is import the Active Directory module.Import-Module Active Directory $c = "oldcompany" Now, I need to retrieve all the users in the test organizational unit (OU). I specify the OU as the value for the Search Base parameter. If I did not need to access individual portions of the user object as it crosses the pipeline, I could have directly piped the user objects to the Set-ADUser cmdlet.For example, if I wanted to specify only the company name, I could have used the command shown here.Refer to the documentation references below the script for more information about the specific cmdlets and how to use the Active Directory module for Power Shell. $Finance Users = Get-ADUser -Filter * -Search Base "OU=Finance, OU=User Accounts, DC=FABRIKAM, DC=COM" # Iterate the users and update the department and title attributes in AD.foreach($Finance User in $Finance Users) The example uses the Instance parameter of Set-ADUser to update each user in the OU.
This can be a bit confusing when trying to update an older script that used ADSI.
Summary: Microsoft Scripting Guy, Ed Wilson, shows how to use Windows Power Shell to modify existing user accounts in Active Directory. The other day, I recorded a Tech Net Radio podcast with Blain Barton and Matt Hester named, “The 10 non-scary things about Windows Power Shell 3.0.” It should be released today, and it will be available through my Learn Windows Power Shell page at the Script Center.
All of the Tech Net Radio podcasts are linked at the bottom of the page.
I have been doing a monthly series with Blain for more than a year, so there are quite a few posts in the series.
Note This is the second in a series of posts about creating a test Active Directory environment.