John Davies
asked on
Question About Out-Grid
Hi, I hope you can help with a question I have.
I have a User CSV file and I want the outgrid of licenses to be selectable and populate the line
$server = read-host 'SELECT A LICENSE PRODUCT TO ADD TO USER' HERE
So, if I run the script it will loop through the users, ask what CSV file you want to open and then open the out-grid showing licenses available on the tenant. It is here I want to select multiple option of licenses and pass the selected items into the next prompted line in powershell, this is at the moment a manual process of typing them out, I want this to populate from the selections made on the out-grid.
#CSV file picker module start
Function Get-FileName($initialDirec tory)
{
[System.Reflection.Assembl y]::LoadWi thPartialN ame("Syste m.windows. forms") |
Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenF ileDialog
$OpenFileDialog.initialDir ectory = $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"
#Window with list of available 365 licenses and their names
Get-MsolAccountSku | out-gridview -Title "Work Scripts" -passthru
#Input window where you provide the license package's name
$server = read-host 'SELECT A LICENSE/PRODUCT TO ADD TO USER:'
#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 "$server"
}
#Result report on licenses assigned to imported users
import-csv $path | Get-MSOLUser | out-gridview
Many thanks
John
I have a User CSV file and I want the outgrid of licenses to be selectable and populate the line
$server = read-host 'SELECT A LICENSE PRODUCT TO ADD TO USER' HERE
So, if I run the script it will loop through the users, ask what CSV file you want to open and then open the out-grid showing licenses available on the tenant. It is here I want to select multiple option of licenses and pass the selected items into the next prompted line in powershell, this is at the moment a manual process of typing them out, I want this to populate from the selections made on the out-grid.
#CSV file picker module start
Function Get-FileName($initialDirec
{
[System.Reflection.Assembl
Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenF
$OpenFileDialog.initialDir
$OpenFileDialog.filter = "All files (*.*)| *.*"
$OpenFileDialog.ShowDialog
$OpenFileDialog.filename
}
#CSV file picker module end
#Variable that holds CSV file location from file picker
$path = Get-FileName -initialDirectory "C:\csv"
#Window with list of available 365 licenses and their names
Get-MsolAccountSku | out-gridview -Title "Work Scripts" -passthru
#Input window where you provide the license package's name
$server = read-host 'SELECT A LICENSE/PRODUCT TO ADD TO USER:'
#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 "$server"
}
#Result report on licenses assigned to imported users
import-csv $path | Get-MSOLUser | out-gridview
Many thanks
John
ASKER
Thanks OBda
I can see this working, however it doesnt populate the line after select a license product to add to user What I get is the license info displayed. What i am looking for is to populate this line (see image) from the selections made.
CODE where I have added your multiple line
#CSV file picker module start
Function Get-FileName($initialDirec tory)
{
[System.Reflection.Assembl y]::LoadWi thPartialN ame("Syste m.windows. forms") |
Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenF ileDialog
$OpenFileDialog.initialDir ectory = $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 "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 ...
} Else {
"Operation canceled"
}
#Input window where you provide the license package's name
$server = read-host 'SELECT A LICENSE PRODUCT TO ADD TO USER'
#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 "$server"
}
#Result report on licenses assigned to imported users
import-csv $path | Get-MSOLUser | out-gridview
Thanks for your help.
John
2016-10-06_13-15-20.png
I can see this working, however it doesnt populate the line after select a license product to add to user What I get is the license info displayed. What i am looking for is to populate this line (see image) from the selections made.
CODE where I have added your multiple line
#CSV file picker module start
Function Get-FileName($initialDirec
{
[System.Reflection.Assembl
Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenF
$OpenFileDialog.initialDir
$OpenFileDialog.filter = "All files (*.*)| *.*"
$OpenFileDialog.ShowDialog
$OpenFileDialog.filename
}
#CSV file picker module end
#Variable that holds CSV file location from file picker
$path = Get-FileName -initialDirectory "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 ...
} Else {
"Operation canceled"
}
#Input window where you provide the license package's name
$server = read-host 'SELECT A LICENSE PRODUCT TO ADD TO USER'
#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 "$server"
}
#Result report on licenses assigned to imported users
import-csv $path | Get-MSOLUser | out-gridview
Thanks for your help.
John
2016-10-06_13-15-20.png
The Out-GridView replaces the Read-Host; you won't need that anymore.
You can work directly with the contents of $Selection.
You can work directly with the contents of $Selection.
ASKER
Hi Mate, looks like it is failing on the $Selection variable, have called it at the end of Set-MsolUserLicense - AddLicenses
}
#CSV file picker module end
#Variable that holds CSV file location from file picker
$path = Get-FileName -initialDirectory "C:\BulkUpload\BulkUpload. 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 ...
} Else {
"Operation canceled"
}
#CSV import command and mailbox creation loop
import-csv $path | foreach {
New-Msoluser -userPrincipalName $_.UserPrincipalName -displayname $_.displayname -firstname $_.firstname -lastname $_.lastname -password $_.Password -usagelocation "GB" | Set-MsolUserLicense -AddLicenses $Selection
}
#Result report on licenses assigned to imported users
import-csv $path | Get-MSOLUser | out-gridview
ERROR
Set-MsolUserLicense : Unable to assign this license because it is invalid. Use the Get-MsolAccountSku cmdlet to retrieve a list of valid licenses.
At C:\BulkUpload\BulkUpload1. ps1:31 char:172
+ ... ord -usagelocation "GB" | Set-MsolUserLicense -AddLicenses $Selection
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~
+ CategoryInfo : OperationStopped: (Microsoft.Onlin...countSk uDetails:S tring) [Set-MsolUserLicense], MicrosoftOnlineException
+ FullyQualifiedErrorId : Invalid License Assignment,Microsoft.Onlin e.Administ ration.Aut omation.Se tUserLicen se
This has retrieved the users from the CSV, stored my selection in the $selection variable and am trying to assign that variable to the users when creating the accounts.
Stumped and thank you for your help so far.
John
}
#CSV file picker module end
#Variable that holds CSV file location from file picker
$path = Get-FileName -initialDirectory "C:\BulkUpload\BulkUpload.
"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 ...
} Else {
"Operation canceled"
}
#CSV import command and mailbox creation loop
import-csv $path | foreach {
New-Msoluser -userPrincipalName $_.UserPrincipalName -displayname $_.displayname -firstname $_.firstname -lastname $_.lastname -password $_.Password -usagelocation "GB" | Set-MsolUserLicense -AddLicenses $Selection
}
#Result report on licenses assigned to imported users
import-csv $path | Get-MSOLUser | out-gridview
ERROR
Set-MsolUserLicense : Unable to assign this license because it is invalid. Use the Get-MsolAccountSku cmdlet to retrieve a list of valid licenses.
At C:\BulkUpload\BulkUpload1.
+ ... ord -usagelocation "GB" | Set-MsolUserLicense -AddLicenses $Selection
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (Microsoft.Onlin...countSk
+ FullyQualifiedErrorId : Invalid License Assignment,Microsoft.Onlin
This has retrieved the users from the CSV, stored my selection in the $selection variable and am trying to assign that variable to the users when creating the accounts.
Stumped and thank you for your help so far.
John
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Bang on Mate, accountskuid did it :-) thanks for all your help and your patience.
Cheers
John
Cheers
John
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