Runbook to apply license to users won't work in Power Automate, but works in testing and Powershell

ServIT Administrator 1 Reputation point


I am working on a Power Automate Flow that creates a user from a SharePoint form and applies a Microsoft License to the user. The flow creates the user from the form correctly but will not apply a license to that user. The runbook seems to work as designed when testing, as I have seen it apply a license from the testing screen in Runbooks. I have also been able to copy and paste each line of code from the runbook into PowerShell and that correctly applied the license. For some reason, the flow just wont work, even when the flow shows no errors. Please help.


Param (
[string] $Employee = ""
$credObject = Get-AutomationPSCredential -Name "ScriptServiceAccount"
Connect-AzureAD -Credential $credObject
$User = Get-AzureADUser -ObjectId $Employee
Set-AzureADUser -ObjectId $User.ObjectId -UsageLocation US
$StandardLicense = Get-AzureADSubscribedSku | Where {$_.SkuId -eq "4b9405b0-7788-4568-add1-99614e613b69"}
$License = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense
$License.SkuId = $StandardLicense.SkuId
$LicensesToAssign = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses
$LicensesToAssign.AddLicenses = $License
Set-AzureADUserLicense -ObjectId $User.ObjectId -AssignedLicenses $LicensesToAssign


Get-AzureADUser : Error occurred while executing GetUser Code: Request_ResourceNotFound Message: Resource 'email@keyman .net' does not exist or one of its queried reference-property objects are not present. RequestId: c4ecf8e4-b895-4a19-b294-74cbd34e18ee DateTimeStamp: Mon, 07 Mar 2022 20:13:40 GMT HttpStatusCode: NotFound HttpStatusDescription: Not Found HttpResponseStatus: Completed At line:6 char:10 + $User = Get-AzureADUser -ObjectId $Employee + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Get-AzureADUser], ApiException + FullyQualifiedErrorId : Microsoft.Open.AzureAD16.Client.ApiException,Microsoft.Open.AzureAD16.PowerShell.GetUser

Set-AzureADUser : Cannot bind argument to parameter 'ObjectId' because it is null. At line:7 char:28 + Set-AzureADUser -ObjectId $User.ObjectId -UsageLocation US + ~~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Set-AzureADUser], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Open.AzureAD16.PowerShell.SetUser

Set-AzureADUserLicense : Cannot bind argument to parameter 'ObjectId' because it is null. At line:13 char:35 + Set-AzureADUserLicense -ObjectId $User.ObjectId -AssignedLicenses ... + ~~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Set-AzureADUserLicense], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Open.AzureAD16.PowerShell.SetUserLicenses



Not Monitored
Not Monitored
Tag not monitored by Microsoft.
36,473 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Dave Patrick 426.2K Reputation points MVP

    Power automate is not currently supported here on Q&A. The product group for Power automate actively monitors questions in dedicated forums here.

    --please don't forget to upvote and Accept as answer if the reply is helpful--