How to check if an account is licenced after backsync following update to 8.1.3

Hi,

I've recently updated to 8.1.3 and I'm having trouble with one of the custom scripts since it uses a newer version of powershell.  We have a hybrid setup and when we create users we aren't creating a mailbox.  Instead Exchange online is creating a mailbox when Azure syncs with the cloud.  Then when the backsync happens Active Roles checks that accounts have a icence assigned and then sets a custom attribute we created (edsvaRemoteMailboxCreation, bad name tbh), which then runs another script that adds the exchange attributes we want.  The second part is working fine, but since we updated the licence check isn't working properly.

Old script - 

$MSOLSession = Connect-msolservice -Credential $credential
$UserPN = $DirObj.get("UserPrincipalName")
$User = Get-MsolUser -userprincipalname $UserPN
if ($User.islicensed -eq $true)
{
$user = ($user.userprincipalname)
Set-QADUser $User -proxy -objectAttributes @{edsvaRemoteMailboxCreation=$true}
}
}

Initially after update I was getting an error on the first line, so I replaced that with:

$MSOLSession = Connect-ExchangeOnline -Credential $credential

I can run this script manually with powershell and it works but the new Active Roles doesn't like it when running as part of a workflow.  In Change history I get an error:

  • At line: 6 char:16. Could not load type 'System.IdentityModel.Tokens.JwtSecurityToken' from assembly 'System.IdentityModel.Tokens.Jwt, Version=6.22.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

I had a play with it and changed the script to use the Assigned licenses attribute instead, coming up with this:

$Licence = get-qaduser -proxy $UserPN -IncludedProperties edsaAzureUserAssignedLicenses,edsvaAzureObjectID | select edsaAzureUserAssignedLicenses
if ($Licence ="*disabledplans*")
{
Set-QADUser $UserPN -proxy -objectAttributes @{edsvaRemoteMailboxCreation=$true}
}
}

That seemed to work perfectly until I thought to check what it would do on someone who doesn't have a license. It makes the attribute true even if the AssignedLicenses attribute is blank!  Is this something anyone else has tried to do or do you have any suggestions please?

Thanks

Charlene

Parents Reply Children
  • Hi,   and  

    Thanks for the suggestions. Stu, your correction didn't cause an error, but it didn't complete the script either so I'm not sure where that went wrong. I'd tried using not $null before but that didn't work.

    Johnny, I missed a line from the start, we've been feeding in the login details via a clixml file since we started that still worked even after a previous update that stopped Basic Auth, at least for now.  I'll have a look at your method though, I did notice that to connect to Azure needed a certificate key this time that it didn't before so that may well be a smoother way of doing it.  

    Regarding group based licensing, we already do assign licenses via groups, which then assign the license in Azure when it syncs with ADConnect.  The issue with creating a mailbox in EXO is it doesn't add the required external forwarding email address for some reason so this workflow was created to compensate for that.  It was set up to add the attributes after the backsync, but only after checking the account actually has a license to allow for cases when they run out so the user doesn't get a mailbox.  The whole thing was set up by another team months before we started using Active Roles; before that the mailboxes were being created on on-prem exchange and then migrated up by the exchange admin team but this workflow negates that requirement.

  • Some food for thought on the licensing side of things: you may recall that there was/is an IsLicensed property returned by the msol commands. I don't have the graph property set memorized (yet). LOL But I imagine that there is something similar in there. That would allow you to detect a licensed state of the object.

  • Aye, if I can't get this method to work using Graph will probably be my next option. I'm going on leave for two weeks so don't want to change anything too drastic right now lol.  At the moment the script works as long as the licenses don't run out (knock on wood)