Get-OMECurrentUser.ps1

Function Get-OMECurrentUser
{

    <#
    .SYNOPSIS
        Can be used to access information about the currently authenticated
        user.
    .DESCRIPTION
        Can be used to access information about the currently authenticated
        user.
    .PARAMETER Session
        Specifies the Session Id for the OME server.
 
    .EXAMPLE
        Get-OMECurrentUser
        UserName UserType
        -------- --------
        John.Doe OMEAdministrator
     
    .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/
    #>
  

    [CmdletBinding(
    )]
    Param(
        $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+"/CurrentUser"
            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.GetCurrentUserResponse.GetCurrentUserResult
                $user=Convert-XMLtoPSObject -xml $result -ObjectType "OME.User"
                $user.PSObject.Properties.Remove('i')
                $user.UserType=[OMEUserRole]$user.UserType
                return $user
            }
        }
        Catch {
            Out-OMEException -Exception $_
        }
    }
    
    End{}                
}