Saturday, September 2, 2023

Availability of Teams user using Microsoft.Graph and Microsoft.Graph.CloudCommunications communication module

Availability of Teams user using Microsoft.Graph and Microsoft.Graph.CloudCommunications Poweshell module

```sh
#Install Module 
Install-Module Microsoft.Graph -Scope CurrentUser
Install-Module Microsoft.Graph.CloudCommunications

#Import Module 
Import-Module Microsoft.Graph
Import-Module Microsoft.Graph.CloudCommunications

# Connect to Microsoft Graph

Connect-MgGraph

# Fina required permission for Get-MgCommunicationPresenceByUserId

Find-MgGraphCommand -command Get-MgCommunicationPresenceByUserId  | Select -First 1 -ExpandProperty Permissions

# Grant scope of access 
Connect-MgGraph -Scopes "Presence.Read.All","Presence.Read"

# get user details using  Microsoft Graph
$user1 = Get-MgUser -Filter "displayName eq 'Rajesh'"
$user2 = Get-MgUser -All | Where-Object {$_.DisplayName -like "*Mark*"}
$params = @{
			ids = @(
                  $user1.Id
                  $user2.Id
				)
		}


# Get Presence  by user id 
#Get-MgCommunicationPresenceByUserId -BodyParameter $params


# Get Presence by user id for Availability other than offline ,DoNotDisturb ,BeRightBack, Away

Get-MgCommunicationPresenceByUserId -BodyParameter $params | where Availability  -NotIn 'Offline','DoNotDisturb','BeRightBack','Away'

# Get Presence by user id who are available 

Get-MgCommunicationPresenceByUserId -BodyParameter $params | where Availability  -EQ 'Available'


#There is other way Get Presence for user id
 
 Get-MgUserPresence -UserId $user1.Id


```

No comments:

Post a Comment