Accessing enum name in PowerShell
<p>I am working on PowerShell a script and I've been having a difficult time using enum types. I perform a REST call to SharePoint Online to get information about a particular group. </p>

<pre><code>$group = Invoke-SPORestMethod -Url "https://tenant.sharepoint.com/sites/site/_api/web/RoleAssignments/GetByPrincipalId(8)?`$expand=RoleDefinitionBindings"
$group.RoleDefinitionBindings.results[0].RoleTypeKind
</code></pre>

<p>It returns an int, RoleTypeKind, that is an enum in  <code>[Microsoft.SharePoint.Client.RoleType]</code>. I'm having difficulty accessing the name property of the assciated enum value. I'm currently doing it like this but it seems horribly wrong:</p>

<pre><code>function getGroupPermissionKind([int]$roleType){
    #https://msdn.microsoft.com/en-us/library/office/microsoft.sharepoint.client.roletype.aspx
    [Enum]::GetValues([Microsoft.SharePoint.Client.RoleType]) | foreach {
        $Name = $_
        $Value = ([Microsoft.SharePoint.Client.RoleType]::$_).value__
        if ($Value -eq $roleType){
            return $Name
        }
    }
}
</code></pre>

<p>Knowing that <code>$group.RoleDefinitionBindings.results[0].RoleTypeKind</code> returns the proper int of the enum, how can I more directly access the name of the enum rather than with the seemingly janky implementation I've come up with?</p>