forked from Gerenios/AADInternals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OfficeApps.ps1
120 lines (101 loc) · 3.27 KB
/
OfficeApps.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# This script contains functions for OfficeApps
# https://office.microsoft.com/Config15
# Get user Office connections
function Get-UserConnections
{
<#
.SYNOPSIS
Returns user's office connections
.DESCRIPTION
Returns user's office connections
.Example
$cred=Get-Credential
$at=Get-AADIntAccessTokenForOfficeApps -credentials $cred
Get-AADIntUserConnections -AccessToken $at
#>
[cmdletbinding()]
Param(
[Parameter(Mandatory=$False)]
[String]$AccessToken
)
Process
{
# Get from cache if not provided
$AccessToken = Get-AccessTokenFromCache -AccessToken $AccessToken -ClientID "ab9b8c07-8f02-4f72-87fa-80105867a763" -Resource "https://officeapps.live.com"
$headers = @{
"Authorization"="Bearer $AccessToken"
}
$response=Invoke-RestMethod -UseBasicParsing -Uri "https://odc.officeapps.live.com/odc/servicemanager/userconnected" -Headers $headers
return $response.ConnectedServicesResults.ServiceConnections.Connection
}
}
# Get recently used Office file connections
function Get-RecentLocations
{
<#
.SYNOPSIS
Returns user's recent office file locations
.DESCRIPTION
Returns user's recent office file locations
.Example
$cred=Get-Credential
$at=Get-AADIntAccessTokenForOfficeApps -credentials $cred
Get-AADIntRecentLocations -AccessToken $at
#>
[cmdletbinding()]
Param(
[Parameter(Mandatory=$False)]
[String]$AccessToken,
[Parameter(Mandatory=$False)]
[ValidateSet('Word','PowerPoint','OneNote','Excel','Visio','Sway','All')]
[String]$App="All",
[Parameter(Mandatory=$False)]
[Int]$Show=100
)
Process
{
# Get from cache if not provided
$AccessToken = Get-AccessTokenFromCache -AccessToken $AccessToken -ClientID "ab9b8c07-8f02-4f72-87fa-80105867a763" -Resource "https://officeapps.live.com"
$headers = @{
"Authorization"="Bearer $AccessToken"
}
if($App -eq "All")
{
$Apps='Word,PowerPoint,OneNote,Excel,Visio,Sway'
}
else
{
$Apps=$App
}
Invoke-RestMethod -UseBasicParsing -Uri "https://ocws.officeapps.live.com/ocs/locations/recent?apps=$Apps&show=$Show" -Headers $headers
}
}
# Gets documents shared with the given user
function Get-SharedWithUser
{
<#
.SYNOPSIS
Returns the documents shared with the given user
.DESCRIPTION
Returns the documents shared with the given user
.Example
$cred=Get-Credential
$at=Get-AADIntAccessTokenForOfficeApps -credentials $cred
Get-AADIntSharedWithUser -AccessToken $at
#>
[cmdletbinding()]
Param(
[Parameter(Mandatory=$False)]
[String]$AccessToken
)
Process
{
# Get from cache if not provided
$AccessToken = Get-AccessTokenFromCache -AccessToken $AccessToken -ClientID "ab9b8c07-8f02-4f72-87fa-80105867a763" -Resource "https://officeapps.live.com"
$headers = @{
"Authorization"="Bearer $AccessToken"
}
$response=Invoke-RestMethod -UseBasicParsing -Uri "https://ocws.officeapps.live.com/ocs/docs/v2.0/sharedwithme" -Headers $headers
return $response.shared_documents
}
}