-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathGet-SfbClientGroup.ps1
66 lines (51 loc) · 2.11 KB
/
Get-SfbClientGroup.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-SfbClientGroup {
<#
.Synopsis
Get Skype for Business Client group details
.Description
This function queries the Skype for Business client group details and returns the Name, Id and members of the group.
.Example
Get-SfbClientGroup
Returns all Skype for Business client groups created.
.Example
Get-SfbClientGroup -Name 'Other Contacts'
This returns the details (Name, Id and members) of the group Other Contacts.
#>
param (
# The name of the group
[Parameter()]
[String]$Name,
# The Skype for Business application context in which to query for the group.
[Parameter()]
[object]$Context = $SkypeForBusinessClientModuleContext
)
$rest = @{
ContentType = 'application/json'
Headers = $Context.authHeader
}
$myGroupsUri = '{0}/{1}' -f $context.rootUri,$Context.application._embedded.people._links.myGroups.href
$myGroups = Invoke-RestMethod -Method Get -Uri $myGroupsUri @rest
# Three items to return: pinnedGroup (Favorites), defaultGroup (Other Contacts by default) and group
[array]$allMyGroups = 'pinnedGroup','defaultGroup' | ForEach-Object {
$groupMemberUri = '{0}/{1}' -f $Context.rooturi,$myGroups._embedded.$_._links.groupContacts.href
[pscustomobject]@{
name = $myGroups._embedded.$_.name
id = $myGroups._embedded.$_.id
members = (Invoke-RestMethod -Method Get -Uri $groupMemberUri @rest)._embedded.contact
}
}
$allMyGroups += $myGroups._embedded.group | ForEach-Object {
$groupMemberUri = '{0}/{1}' -f $Context.rooturi,$_._links.groupContacts.href
[pscustomobject]@{
name = $_.name
id = $_.id
members = (Invoke-RestMethod -Method Get -Uri $groupMemberUri @rest)._embedded.contact
}
}
If($Name) {
Write-Output $allMyGroups | Where-Object {$_.name -eq $Name}
}
Else {
Write-Output $allMyGroups
}
}