Forum Discussion
AdamAtTheMuseum
May 23, 2023Copper Contributor
MS Microsoft Graph PowerShell SDK to assign licenses in bulk from a csv file
Hello I have a .csv file with over 400 users in it in the form of the email address of each user. I need to assign a Microsoft 365 license to each user as a one-off process. They currently have thr...
- May 23, 2023
Figure Out your SKUID's here
Connect-MgGraph -Scopes User.ReadWrite.All, Directory.ReadWrite.All
$CSV = Import-CSV -Path C:\Test\users.csv #-Delimiter ";"
ForEach ($User in $CSV)
{
$UPN = $User.Email
Set-MgUserLicense -UserId $UPN -AddLicenses @{SkuId = 'cb10e6cd-9da4-4992-867b-67546b1db821'} -RemoveLicenses @()
}
Regards
Andres
Andres-Bohren
May 23, 2023Steel Contributor
Figure Out your SKUID's here
Connect-MgGraph -Scopes User.ReadWrite.All, Directory.ReadWrite.All
$CSV = Import-CSV -Path C:\Test\users.csv #-Delimiter ";"
ForEach ($User in $CSV)
{
$UPN = $User.Email
Set-MgUserLicense -UserId $UPN -AddLicenses @{SkuId = 'cb10e6cd-9da4-4992-867b-67546b1db821'} -RemoveLicenses @()
}
Regards
Andres
- emansqiJun 04, 2023Copper Contributor
my CSV files is formatted like thisemail
email address removed for privacy reasons
email address removed for privacy reasons
email address removed for privacy reasons
email address removed for privacy reasons
I tried using your recommendation but my script is below$CSV = Import-Csv C:\changelicense\batch01.csv #-Delimiter ";"
ForEach ($User in $CSV) {
$UPN = $User.email
Set-MgUserLicense -UserId $UPN -AddLicenses @() -RemoveLicenses @{SkuId = $Mf3Sku.SkuId}
Set-MgUserLicense -UserId $UPN -AddLicenses @{SkuId = $0e3Sku.SkuId} -RemoveLicenses @()
}but I'm getting
Cannot convert the literal 'System.Collections.Hashtable' to the expected type 'Edm.Guid'.
what am I'm missing? thanks in advance
- Andres-BohrenJun 04, 2023Steel Contributor
II think the CSV is fine
Try to replace the SKU with the ID as a String "skuid"
Or add $() to your SKUId
Example:
Set-MgUserLicense -UserId $UPN -AddLicenses @{SkuId = $($0e3Sku.SkuId) }Regards
Andres
- emansqiJun 04, 2023Copper Contributor
Thanks for responding Andres-Bohren
The licenses is working is use it for one email address at a time. that I'm getting error at is on -UserId
errors says cannot bind because UserID is empty string. I can't seem to pull the list of email addresses from the imported CSV. when I run the command using the same address on the CSV at one time, it works.
- AdamAtTheMuseumMay 24, 2023Copper ContributorThanks everyone I have managed to figure it out with your help!