Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.
#CSV file picker module start
Function Get-FileName($initialDirectory) {
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.filter = "All files (*.*)| *.*"
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
}
#CSV file picker module end
#Variable that holds CSV file location from file picker
$path = Get-FileName -initialDirectory "C:\csv"
"Waiting for you to select something from the dialog ..."
$Selection = Get-MsolAccountSku | Out-GridView -Title "Work Scripts" -OutputMode Multiple
If ($Selection) {
"Selected licenses: "
$Selection | Format-List
## Do something with the selection ...
#CSV import command and mailbox creation loop
import-csv $path | foreach {
New-Msoluser -userPrincipalName $_.UserPrincipalName -displayname $_.displayname -firstname $_.firstname -lastname $_.lastname -password $_.Password -usagelocation "us" |
set-msoluserlicense -addlicenses $Selection.PROPERTY
}
#Result report on licenses assigned to imported users
import-csv $path | Get-MSOLUser | out-gridview
} Else {
"Operation canceled"
}
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Open in new window
To restrict the selection to a single line, use "-OutputMode Single" instead of "Multiple".So in your case, you can do something like this (and you may want to pass the Get-MsolAccountSku output through a Select-Object, like the example above):
Open in new window