How can I remove a User Role from a list of users using ISHRemote?

Hi,

I don't know if it is possible to get down to this granular level using ISHRemote but I would like to filter through list of users that have a User Role and remove that User Role from each of those User's accounts. I need to do this based on the assumption that I cannot remove the User Role while it is associated with User acccounts.

Any advice appreciated,

Regards,

Ann

emoji
Parents
  • Hi Ann,

    Below a code snippet that at least would get you started, it is for you to tune/debug the edge cases. Should get you going though to remove the User Role which is blocked by referential integrity

    # Building up the sample, which fields exist
    Get-IshTypeFieldDefinition | Out-GridView
    
    New-IshSession ...
    # All user roles
    $userRoles = Find-IshUserRole
    # All user roles 'element names', so the readable identifiers that do not change when you rename the label (aligned between LOV and CardReference fields)
    $userRoles.fishuserrolename_none_element
    # So assuming VUSERROLETRANSLATOR for this sample
    
    # All users having a certain user role
    $filterMetadata = Set-IshMetadataFilterField -Level None -Name FISHUSERROLES -FilterOperator In -ValueType Element -Value "VUSERROLETRANSLATOR"
    $users = Find-IshUser -MetadataFilter $filterMetadata
    
    foreach ($user in $users)
    {
        # This multi-value field is not typed, it is a comma-space (, ) separated string, something for future OpenApi to come :)
        [System.Collections.ArrayList]$userRoles = $user.fishuserroles_none_element  -split ", "
        # Parsed into an ArrayList object, removing the wanted role
        $userRoles.Remove("VUSERROLETRANSLATOR")
        # Updating the current user with the reduced user roles and updating/setting the user profile in the CMS
        $user | 
        Set-IshMetadataField -Level None -Name FISHUSERROLES -ValueType Element -Value ($userRoles -join ", ") |
        Set-IshUser
    }

    -Dave

    emoji
Reply
  • Hi Ann,

    Below a code snippet that at least would get you started, it is for you to tune/debug the edge cases. Should get you going though to remove the User Role which is blocked by referential integrity

    # Building up the sample, which fields exist
    Get-IshTypeFieldDefinition | Out-GridView
    
    New-IshSession ...
    # All user roles
    $userRoles = Find-IshUserRole
    # All user roles 'element names', so the readable identifiers that do not change when you rename the label (aligned between LOV and CardReference fields)
    $userRoles.fishuserrolename_none_element
    # So assuming VUSERROLETRANSLATOR for this sample
    
    # All users having a certain user role
    $filterMetadata = Set-IshMetadataFilterField -Level None -Name FISHUSERROLES -FilterOperator In -ValueType Element -Value "VUSERROLETRANSLATOR"
    $users = Find-IshUser -MetadataFilter $filterMetadata
    
    foreach ($user in $users)
    {
        # This multi-value field is not typed, it is a comma-space (, ) separated string, something for future OpenApi to come :)
        [System.Collections.ArrayList]$userRoles = $user.fishuserroles_none_element  -split ", "
        # Parsed into an ArrayList object, removing the wanted role
        $userRoles.Remove("VUSERROLETRANSLATOR")
        # Updating the current user with the reduced user roles and updating/setting the user profile in the CMS
        $user | 
        Set-IshMetadataField -Level None -Name FISHUSERROLES -ValueType Element -Value ($userRoles -join ", ") |
        Set-IshUser
    }

    -Dave

    emoji
Children
No Data