Hello,
I need a script that can assign Office 365 licences based on an AD Attribute value.
What I want though is the following:
· Inside the script clearly label the attribute in use in case the I wants to use a different attribute using non-script people so they can easily change the attribute. Start with ‘extenstionAttribute1’ for now?
·It queries all unlicensed users and only assigns a licence where the attribute is set
·The attribute should contain the value equal to the licence type: ie: an A1 licence the attribute has the value A1, E1 licence has an E1 value etc for all the licence types
oThis needs to have the ability to add new licence types if / as Microsoft release or change them
·It needs to log the changes made to a new file (not overwrite the existing file) each time it is run. Simply log the Userid and licence assigned to allow auditing.
#_{_{_
$AdUser=Get-ADUser -filter {UserPrincipalName-eq$user.UserPrincipalName} -Properties extensionAttribute1
foreach ($user in (Get-MsolUser))
{
if(!($user.IsLicensed))
{
$AdUser = Get-ADUser -filter {UserPrincipalName -eq $user.UserPrincipalName} -Properties extensionAttribute1
Set-MsolUser -UserPrincipalName $user.UserPrincipalName -UsageLocation "AU"
if ($AdUser.extensionAttribute1 -eq "Stud")
{
$MyO365Sku = New-MsolLicenseOptions -AccountSkuId "xxxxx:STANDARDWOFFPACK_STUDENT" -DisabledPlans SHAREPOINTWAC_EDU, MCOSTANDARD, SHAREPOINTSTANDARD_EDU
Set-MsolUserLicense -UserPrincipalName $user.UserPrincipalName -AddLicenses "xxxxx:STANDARDWOFFPACK_STUDENT" -LicenseOptions $MyO365Sku
}
if ($AdUser.extensionAttribute1 -eq "Pers")
{
$MyO365Sku = New-MsolLicenseOptions -AccountSkuId "xxxxx:STANDARDWOFFPACK_FACULTY" -DisabledPlans SHAREPOINTWAC_EDU, MCOSTANDARD, SHAREPOINTSTANDARD_EDU
Set-MsolUserLicense -UserPrincipalName $user.UserPrincipalName -AddLicenses "xxxxx:STANDARDWOFFPACK_FACULTY" -LicenseOptions $MyO365Sku
}
}
}
foreach ($user in (Get-MsolUser -UnlicensedUsersOnly))
{
$AdUser = Get-ADUser -filter {UserPrincipalName -eq $user.UserPrincipalName} -Properties extensionAttribute1
Set-MsolUser -UserPrincipalName $user.UserPrincipalName -UsageLocation "AU"
if ($AdUser.extensionAttribute1 -eq "Stud")
{
$MyO365Sku = New-MsolLicenseOptions -AccountSkuId "xxxxx:STANDARDWOFFPACK_STUDENT" -DisabledPlans SHAREPOINTWAC_EDU, MCOSTANDARD, SHAREPOINTSTANDARD_EDU
Set-MsolUserLicense -UserPrincipalName $user.UserPrincipalName -AddLicenses "xxxxx:STANDARDWOFFPACK_STUDENT" -LicenseOptions $MyO365Sku
}
if ($AdUser.extensionAttribute1 -eq "Pers")
{
$MyO365Sku = New-MsolLicenseOptions -AccountSkuId "xxxxx:STANDARDWOFFPACK_FACULTY" -DisabledPlans SHAREPOINTWAC_EDU, MCOSTANDARD, SHAREPOINTSTANDARD_EDU
Set-MsolUserLicense -UserPrincipalName $user.UserPrincipalName -AddLicenses "xxxxx:STANDARDWOFFPACK_FACULTY" -LicenseOptions $MyO365Sku
}
}
#_}_}_
I have the above script but showing some unknown error. Kindly help with working script.
Thanks,
DSKOLI