-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathGet-SfbClientContactPresence.ps1
66 lines (58 loc) · 2.26 KB
/
Get-SfbClientContactPresence.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
function Get-SfbClientContactPresence {
<#
.Synopsis
Get the presence status of a contact
.Description
This function queries the presence of a Skype for Business Client contact. For example the presence can be Online, Away, BeRightBack, Busy, DoNotDisturb or Offline
.Example
Get-SfbClientContact -Name Foo | Get-SfbClientContactPresence
This get's the presence of all users returned by the Get-SfbClientContact function.
#>
[CmdletBinding()]
param (
# The name of the contact
[Parameter(
Mandatory,
ValueFromPipelineByPropertyName
)]
[String]$Name,
# PresenceUri for the contact
[Parameter(
ValueFromPipelineByPropertyName
)]
[object]$_links,
# The Skype for Business application context
[Parameter()]
[Object]$Context = $SkypeForBusinessClientModuleContext
)
Begin {
$json = 'application/json'
}
Process {
if($_links) {
$presenceUri = '{0}{1}' -f $Context.rootUri,$_links.contactPresence.href
Invoke-RestMethod -Method Get -Uri $presenceUri -ContentType $json -Headers $Context.authHeader | ForEach-Object {
[pscustomobject]@{
name = $Name
availability = $_.availability
deviceType = $_.deviceType
lastActive = $_.lastActive
}
}
}
else {
$userPresence = Get-SfbClientContact -Name $Name -Context $Context -PipelineVariable contact | ForEach-Object {
$presenceUri = '{0}{1}' -f $Context.rootUri,$_._links.contactPresence.href
Invoke-RestMethod -Method Get -Uri $presenceUri -ContentType $json -Headers $Context.authHeader | ForEach-Object {
[pscustomobject]@{
name = $contact.name
availability = $_.availability
deviceType = $_.deviceType
lastActive = $_.lastActive
}
}
}
Write-Output $userPresence
}
}
}