Share via

Creating function in powershell to edit user via MgGraph SDK

Alessandro Pellitteri 0 Reputation points
2023-08-03T11:36:56.33+00:00

Hi, I'm writing a function in powershell which edits the given parameters.
The function parameters look like this:

function EditUser {
    param (
        [string]$UserId,

        # Generic Information
        [string]$DisplayName = $null,
        [string]$GivenName = $null,
        [string]$Surname = $null,
        [string]$AccountEnabled = $null,
        [string]$JobTitle = $null,
        [string]$Department = $null,
        [string]$OfficeLocation = $null,
        [string]$UserType = $null,

        # Contacts
        [string]$Mail = $null,
        [string[]]$BusinessPhones = @(),
        [string]$MobilePhone = $null,
        [string]$FaxNumber = $null,
        [string]$MailNickname = $null,
        [string[]]$OtherMails = @(),

        # Place
        [string]$Country = $null,
        [string]$City = $null,
        [string]$State = $null,
        [string]$StreetAddress = $null,
        [string]$PostalCode = $null,

        # Other
        [int]$DeviceEnrollmentLimit = $null,
        [string]$Birthday = $null,
        [string]$PreferredLanguage = $null,
        [string]$PreferredName = $null,
        [string]$UsageLocation = $null
    )

But when it executes the following command...

$userToUpdate = Get-MgUser -Filter "id eq '$UserId'" -Select `
        displayName, givenName, surname, accountEnabled, jobTitle, department, `
        officeLocation, userType, mail, businessPhones, mobilePhone, faxNumber, `
        mailNickname, otherMails, country, city, state, streetAddress, postalCode, `
        deviceEnrollmentLimit, birthday, preferredLanguage, preferredName, usageLocation

...I get the following error:

Get-MgUser : This operation target is not yet supported.
Status: 501 (NotImplemented)
ErrorCode: NotImplemented
Date: 2023-08-03T11:33:11
Headers:
Transfer-Encoding             : chunked
Vary                          : Accept-Encoding
Strict-Transport-Security     : max-age=31536000
request-id                    : 
client-request-i
x-ms-ags-diagnostic           : {"ServerInfo":{"DataCenter":"North
Europe","Slice":"E","Ring":"4","ScaleUnit":"000","RoleInstance":"DU6PEPF00002DB7"}}
Date                          : Thu, 03 Aug 2023 11:33:10 GMT
In C:\Scripts\PowerShell\Intune powershell.ps1:340 car:5
+     $userToUpdate = Get-MgUser -Filter "id eq '$UserId'" -Select `
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: ({ ConsistencyLe...ndProperty =  }:<>f__AnonymousType40`8) [Get-MgUser
   _List], Exception
    + FullyQualifiedErrorId : NotImplemented,Microsoft.Graph.PowerShell.Cmdlets.GetMgUser_List

I don't get which parameter(s) is giving me the error.

Windows for business | Windows Server | User experience | PowerShell
Microsoft Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Microsoft Graph
0 comments No comments

2 answers

Sort by: Most helpful
  1. Marilee Turscak-MSFT 37,396 Reputation points Microsoft Employee Moderator
    2023-08-04T21:13:32.5766667+00:00

    Hi @Alessandro Pellitteri ,

    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept " the answer.

    Issue:

    You received the error, "This operation target is not yet supported" when trying to create a function in Powershell to edit a set of parameters. When updating the parameters, you were unable to isolate which parameters were triggering the error.

    Solution:

    You figured out that the issue was caused by these parameters: deviceEnrollmentLimit, birthday, preferredLanguage, preferredName

    Certain properties can only be retrieved for individual users and not for a collection of users. https://github.com/microsoftgraph/microsoft-graph-docs/issues/381

    If I missed anything please let me know and I'd be happy to add it to my answer, or feel free to comment below with any additional information. Thank you again for your time and patience throughout this issue.

    Please remember to "Accept Answer" if the answer accurately summarized the solution, so that others in the community facing similar issues can easily find the solution.

    Was this answer helpful?

    0 comments No comments

  2. Alessandro Pellitteri 0 Reputation points
    2023-08-04T10:21:44.1333333+00:00

    I got the solution.
    The parameters giving me problems were the following ones:

    deviceEnrollmentLimit, birthday, preferredLanguage, preferredName
    

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.