web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Runbook to apply licen...
Power Automate
Unanswered

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

(0) ShareShare
ReportReport
Posted on by

 

Summary:

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 won't work, even when the flow shows no errors. Please help.

 

Code:

 

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

 

 

Errors:

Get-AzureADUser : Error occurred while executing GetUser Code: Request_ResourceNotFound Message: Resource 'email@domain.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

 

Flow:

180783-image.png

Categories:

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 424

#2
11manish Profile Picture

11manish 328 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 274

Last 30 days Overall leaderboard