Power shell. Working with CSV’s like you would a database table.

Feb 26, 2020 | Azure, Podcasts, Scripting and programming, Server administration | 0 comments

One of the features I most love about Power shell is it’s ability to let you work with a CSV file just as if it was a database table. Assuming your columns have names at the top of the file, you can select specific items, filter using where and even join them. Here’s a quick example:

$UserToRestore = Import-CSV c:\ps\Azure\AllAzureADUsers.csv | select UserPrincipalName, ObjectId | where UserPrincipalName -eq $EmailAddress
$NewUserPrincipalName = $UserToRestore.UserPrincipalName.Replace('Domain.TLD','SubDomain.onmicrosoft.com')
Restore-MsolUser -ObjectId $UserToRestore.ObjectId -AutoReconcileProxyConflicts -NewUserPrincipalName $NewUserPrincipalName

This is just so useful.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.