DOWNLOAD the free e-book:
FOLLOW ME
Other e-Books:
Monday, June 19, 2017
Powershell: Set AD User "Name" with givenname and surname (it´s the Name that is displayed in ADUC)
Some guys mix up Name with Displayname. So with this command we will change the name you see in ADUC.
Get-aduser tbuntrock -Properties * | foreach { Rename-ADObject $_ -newname ($_.givenname + " " + $_.sn)}
Get-aduser tbuntrock -Properties * | foreach { Rename-ADObject $_ -newname ($_.givenname + " " + $_.sn)}
Labels:
Active Directory,
Powershell,
User Accounts
Tuesday, June 13, 2017
Powershell: Disable AD User from csv and append Description
The file should contain the samaccountnames and looks like:
Script:
$logfile = "C:\admin\VacationUsers.csv"
get-content $logfile |get-aduser -Properties Description | ForEach-Object { Set-ADUser $_ -enabled $false -Description "$($_.Description) DISABLED as requested by HR" }
How it works:
- Define file path
- Just get the users from csv
- Use get-aduser to get description
- do this for each user and...
- Set description
We keep the old Description with $($_.Description) and all that follows will be appended. In my example it is DISABLED as requested by HR.
user1
user2
user3
Script:
$logfile = "C:\admin\VacationUsers.csv"
get-content $logfile |get-aduser -Properties Description | ForEach-Object { Set-ADUser $_ -enabled $false -Description "$($_.Description) DISABLED as requested by HR" }
How it works:
- Define file path
- Just get the users from csv
- Use get-aduser to get description
- do this for each user and...
- Set description
We keep the old Description with $($_.Description) and all that follows will be appended. In my example it is DISABLED as requested by HR.
Labels:
Active Directory,
Powershell,
User Accounts
Subscribe to:
Posts (Atom)