Bulk update AD user details with powershell from CSV / update AD users’ phone numbers

Create a csv file with columns and data, with a command like:

Get-ADUser -Filter “(Enabled -eq ‘True’ -and OfficePhone -eq ‘212-555-1212’)” -Properties * | select samaccountname, officephone |Export-Csv oldphones.csv

samaccountname officephone
John.Jones 212-555-1212 ext. 123
Jane.Jones 212-555-1212 ext. 124

Save it and run this command:

Import-Csv ‘.\phonenums.csv’ | % { Set-ADUser -Identity $_.samaccountname -OfficePhone $_.OfficePhone -WhatIf}

Remove the What If switch to actually make the updates. What if simulates the changes so you can see which users will be updated, but won’t change anything if you made a mistake. Make sure to use SamAccountName and not Name, because the ADUser has to be identified by SamAccountName in the Set-ADUser command.

Decompress multiple gzipped files into one file

E.g. I have multiple old Apache access logs (which are compressed with gzip) and I want to extract them all into one large log.

You can use cat to combine all the gzipped files into one file, then decompress the one large file.

cat *.gz > all.gz
gzip -d all.gz

Blog at WordPress.com.

Up ↑