Avatar of mhmservices
mhmservicesFlag for United States of America

asked on 

Powershell question about Get-ADUser

Hello,

I have a csv file that has employeeID with first_name and Last_name.

employeeID   FirstName      LastName
-----------------   -----------------    ---------------
111                    John               Doe
222                    Jane                Jones

I also set an attribute in AD called extensionAttribute5.  If the value of extensionAttribute5=1 then make the name change else do not.

I have this script:
Import-Csv update.csv | ForEach `
       $employeeID = $_.employeeID
       $SN=$_.LastName
{
      Get-ADUser -LDAPFilter "(employeeID=$employeeID)"| Set-ADUser -replace @{sn=$SN}
}

But the problem is it will change for all users in the file.

How can I put a condition so it would be something like this:
Get-ADUser -LDAPFilter "(employeenumber=$employeenumber)"| If (extensionAttribute5=1) {Set-ADUser -replace @{sn=$SN}}

Thanks.
PowershellActive DirectoryScripting Languages

Avatar of undefined
Last Comment
mhmservices
ASKER CERTIFIED SOLUTION
Avatar of footech
footech
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of mhmservices
mhmservices
Flag of United States of America image

ASKER

Thanks footech, the first solutions worked.
Active Directory
Active Directory

Active Directory (AD) is a Microsoft brand for identity-related capabilities. In the on-premises world, Windows Server AD provides a set of identity capabilities and services, and is hugely popular (88% of Fortune 1000 and 95% of enterprises use AD). This topic includes all things Active Directory including DNS, Group Policy, DFS, troubleshooting, ADFS, and all other topics under the Microsoft AD and identity umbrella.

86K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo