Start-Transcript
connect-azuread
$cohort = read-host "Enter Cohort tag to be licensed (eg. 4.3_DevOps)"
Get-AzureADUser -Filter "startswith(state,'$cohort')" | ForEach-Object { $azureUser = Get-AzureADUser -ObjectId $_
$License = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense
$License.SkuId = "f245ecc8-75af-4f8e-b61f-27d8114de5f3"
$LicensesToAssign = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses
$LicensesToAssign.AddLicenses = $License
Set-AzureADUserLicense -ObjectId $azureUser.ObjectId -AssignedLicenses $LicensesToAssign
}
Can’t seem to find out how to do this, total noob and looking for help or at least being pointed in the right direction, as it always errors out with:
Get-AzureADUser : Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
At AtributeLicenses.ps1:4 char:87
+ ... ohort')" | ForEach-Object { $azureUser = Get-AzureADUser -ObjectId $_
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-AzureADUser], JsonReaderException
+ FullyQualifiedErrorId : Newtonsoft.Json.JsonReaderException,Microsoft.Open.AzureAD16.PowerShell.GetUser
Set-AzureADUserLicense : Cannot bind argument to parameter 'ObjectId' because it is null.
At AtributeLicenses.ps1:10 char:38
+ Set-AzureADUserLicense -ObjectId $azureUser.ObjectId -AssignedLic ...
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Set-AzureADUserLicense], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Open.AzureAD16.PowerShell.SetUs
erLicenses
Any ideas?