microsoftgraph / msgraph-sdk-powershell

Powershell SDK for Microsoft Graph
https://www.powershellgallery.com/packages/Microsoft.Graph
Other
701 stars 168 forks source link

New-MgEntitlementManagementAccessPackageAssignmentRequest | "The property 'TargetId' cannot be found on this object" #1618

Closed omarlucia closed 1 year ago

omarlucia commented 1 year ago

I'm trying to add assignments for an access package in Azure AD entitlement management. For that I'm following this docuemntation, assign-a-user-to-an-access-package-with-powershell

For that I'm using same snippet described just replacing it with my own values. (access package and user id)

Connect-MgGraph -Scopes "EntitlementManagement.ReadWrite.All"
Select-MgProfile -Name "beta"
$accesspackage = Get-MgEntitlementManagementAccessPackage -DisplayNameEq "My access package name" -ExpandProperty "accessPackageAssignmentPolicies"
$policy = $accesspackage.AccessPackageAssignmentPolicies[0]
$req = New-MgEntitlementManagementAccessPackageAssignmentRequest -AccessPackageId $accesspackage.Id -AssignmentPolicyId $policy.Id -TargetId "a43ee6df-3cc5-xxxx-xxxx-ea964ef8e464"

Issue

When i run this i get the next error:

New-MgEntitlementManagementAccessPackageAssignmentRequest : The property 'TargetId' cannot be found on this object.
Verify that the property exists and can be set.

This error dont let me to add user to the access package.

As I see in documentation, 'TargetId" must be not empty with combination 'AccessPackageId' and 'AssignmentPolicyId' parameters.

versions

I currently download ps Microsoft.Graph 1.15.0 (also trying with 1.13.0 version) Install-Module -Name Microsoft.Graph -Scope CurrentUser

Version              Name                                Repository           Description
-------              ----                                ----------           -----------
1.15.0               Microsoft.Graph                     PSGallery            Microsoft Graph PowerShell module
1.15.0               Microsoft.Graph.Applications        PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.Authentication      PSGallery            Microsoft Graph PowerShell Authentication Module.
1.15.0               Microsoft.Graph.Bookings            PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.Calendar            PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.ChangeNotifications PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.CloudCommunications PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.Compliance          PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.CrossDeviceExperie… PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.DeviceManagement    PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.DeviceManagement.A… PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.DeviceManagement.A… PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.DeviceManagement.E… PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.DeviceManagement.F… PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.Devices.CloudPrint  PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.Devices.CorporateM… PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.Devices.ServiceAnn… PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.DirectoryObjects    PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.Education           PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.Files               PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.Financials          PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.Groups              PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.Identity.Directory… PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.Identity.Governance PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.Identity.SignIns    PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.Mail                PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.ManagedTenants      PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.Notes               PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.People              PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.PersonalContacts    PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.Planner             PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.Reports             PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.SchemaExtensions    PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.Search              PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.Security            PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.Sites               PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.Teams               PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.Users               PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.Users.Actions       PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.Users.Functions     PSGallery            Microsoft Graph PowerShell Cmdlets
1.15.0               Microsoft.Graph.WindowsUpdates      PSGallery            Microsoft Graph PowerShell Cmdlets

PowerShell version

PS C:\Users\EIPEA\test> $PSVersionTable.PSVersion

Major  Minor  Patch  PreReleaseLabel BuildLabel
-----  -----  -----  --------------- ----------
7      3      0

Can somebody help me in figureout why error New-MgEntitlementManagementAccessPackageAssignmentRequest: The property 'TargetId' cannot be found on this object. Verify that the property exists and can be set. is showing?

omarlucia commented 1 year ago

For someone struggling the same, i just resolved downgrading Microsoft.Graph version to 1.11.1.

I've tested from 1.16.0, 1.15.0, 1.14.0, 1.13.0, then just go to the most downloaded version 1.11.1 then works. not sure from what version this could be an issue.

peombwa commented 1 year ago

Thanks for bringing this to our attention!

I've traced the issue to how New-MgEntitlementManagementAccessPackageAssignmentRequest custom command is creating an instance of AccessPackageAssignment. It is using the v1.0's AccessPackageAssignment type when instantiating the object. AccessPackageAssignment does not have a TargetId property in v1.0 - https://learn.microsoft.com/en-us/graph/api/resources/accesspackageassignment?view=graph-rest-1.0#properties.

We will issue a bug fix for the issue in next week's release.