Cli-microsoft365: New command: spo userprofile set

Created on 25 Jun 2020  路  4Comments  路  Source: pnp/cli-microsoft365

Usage

spo userprofile set [options]

Description

Sets user profile property for a SharePoint user

Options

| Option | Description |
| ----------------------- | ----------------------------------------- |
| -u, --userName <userName> | Account name of the user |
| -n, --propertyName <propertyName> | The property name of the property to be be set |
| -v, --propertyValue <propertyValue> | The value of the property to be set |
| -o, --output [output] | Output type. json,text. Default text |
| --verbose | Runs command with verbose logging |
| --debug | Runs command with debug logging |

Command example

Updates single value property of a user profile with property name _SPS-JobTitle_ and property value 'Senior Developer'

spo userprofile set --name '[email protected]' --propertyName  'SPS-JobTitle' --propertyValue 'Senior Developer'

Updates multi value property of a user profile with property name _SPS-Skills_ and property values 'CSS', 'HTML'

spo userprofile set --name '[email protected]' --propertyName 'SPS-Skills' --propertyValue 'CSS','HTML'

Remarks

This command requires tenant admin permissions in case of updating properties other than the current logged user.

Example for calling the SharePoint UserProfiles APIs.

This is REST request for updating a single value property that can be implemented in the command. It uses fetch that will have to change within a CLI command with the request library.

fetch(`https://mytenant.sharepoint.com/sites/finder-en/_api/contextinfo`, {
    headers: {
        "Accept": "application/json;odata=nometadata",
        "Content-type": "application/json;odata=verbose"
    },
    method: "POST"
}).then((response) => {
    if (!response.ok) {
        console.log(response);
    }
    return response.json();
}).then((response) => {
    console.log(response);

    fetch(`https://mytenant.sharepoint.com/sites/finder-en/_api/SP.UserProfiles.PeopleManager/SetSingleValueProfileProperty`, {
        headers: {
            "Accept": "application/json;odata=nometadata",
            "Content-type": "application/json;odata=verbose",
            "X-RequestDigest": response.FormDigestValue
        },
        method: "POST",
        body: JSON.stringify({
            'accountName': "i:0#.f|membership|[email protected]",
            'propertyName': "finderCommunityOfPracticeBody1",
            'propertyValue': "Velin Test gfdgf"
        })
    }).then((response) => {
        if (!response.ok) {
            console.log(response);
        }
        return response.json();

    }).then((response) => {
        console.log(response);
    })
})

This is REST request for updating a multi value property that can be implemented in the command. It uses fetch that will have to change within a CLI command with the request library.

fetch(`https://mytenant.sharepoint.com/sites/finder-en/_api/contextinfo`, {
    headers: {
        "Accept": "application/json;odata=nometadata",
        "Content-type": "application/json;odata=verbose"
    },
    method: "POST"
}).then((response) => {
    if (!response.ok) {
        this.handleResponseError(response);
        reject(response);
    }
    return response.json();
}).then((response) => {
    console.log(response);

    fetch(`https://mytenant.sharepoint.com/sites/finder-en/_api/SP.UserProfiles.PeopleManager/SetMultiValuedProfileProperty`, {
        headers: {
            "Accept": "application/json;odata=nometadata",
            "Content-type": "application/json;odata=verbose",
            "X-RequestDigest": response.FormDigestValue
        },
        method: "POST",
        body: JSON.stringify({
            'accountName': "i:0#.f|membership|[email protected]",
            'propertyName': "finderSkills",
            'propertyValues': ["Technology1", "Written Communication2"]
        })
    }).then((response) => {
        if (!response.ok) {
            console.log(response);
        }
        return response.json();
    }).then((response) => {
        console.log(response);
    })
})

Additional Information

Set-PnPUserProfileProperty - https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/set-pnpuserprofileproperty?view=sharepoint-ps

good first issue new feature work in progress

All 4 comments

See remarks from #1670. As for description, I'd suggest we rephrase it to Sets user profile property for a SharePoint user (single property) since the command allows you to update only one property at the time. If we used -u for user, then we could use -n and -v for name and value. What do you think?

Changed according the comments. Thank you!

Hey guys, can I take this up?

All yours Aakash @aakashbhardwaj619 . Thank you for your support!

Was this page helpful?
0 / 5 - 0 ratings