Get-OMEPermissions.ps1

Function Get-OMEPermissions
{

    <#
    .SYNOPSIS
        Gets Permissions by Active Directory SID.
    .DESCRIPTION
        Gets Permissions by Active Directory SID.
    .PARAMETER SID
        Specifies SID of the user.
    .PARAMETER Session
        Specifies the Session Id for the OME server.
 
    .EXAMPLE
        Get-OMEPermissions
 
    .NOTES
        Author: Mike Khar
    .LINK
        http://www.dell.com/support/home/us/en/04/product-support/product/dell-openmanage-essentials-v2.2/research
        https://$Server:$Port/api/OME.svc/UserPermissions/$SID
    #>
  

    [CmdletBinding(
    )]
    Param(
        [parameter(Mandatory=$true)]
        [String]$SID,
        $Session="OMEConnection.DefaultOMESession"
    )
    
    Begin
    {
        $CurrentSession = Get-Variable -Scope Global -Name $Session -ErrorAction SilentlyContinue -ValueOnly
        If (!$CurrentSession) {
            Write-Warning "Please use Set-OMEConnection first"
            Break
            Return
        }
        else {
            $BaseUri="https://"+$CurrentSession.Server+":"+$CurrentSession.Port+"/api/OME.svc"
        }
    }
    
    Process
    {    
        Try {
            $uri=$BaseUri+"/UserPermissions/$SID"
            if ($CurrentSession.Credentials) {
                $result = Invoke-WebRequest -Uri $uri -Credential $CurrentSession.Credentials
            }
            else {
                $result = Invoke-WebRequest -Uri $uri -UseDefaultCredentials
            }
            if ($result.StatusCode -ne 200) {
                Out-OMEException -Exception $_
                return
            }
            else {
                Write-Debug "HTTP request: $uri HTTP status code: $($result.StatusCode)"
                [xml]$xml=$result.Content
                $result=$xml.UserPermissionsResponse.UserPermissionsResult
                return $(Convert-XMLtoPSObject -xml $result -ObjectType "OME.Permissions").Permission
            }
        }
        Catch {
            Out-OMEException -Exception $_
        }
    }
    
    End{}                
}