Skip to content

Commit 1e967fb

Browse files
committed
Merged branch staging into master
2 parents 856c428 + 35f5e4b commit 1e967fb

14 files changed

+977
-65
lines changed

PSMSGraph/Public/Get-AADGroupByDisplayName.ps1

+8-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,15 @@
3636
3737
.OUTPUTS
3838
MSGraphAPI.DirectoryObject.ServicePrincipal
39-
39+
40+
.LINK
41+
http://psmsgraph.readthedocs.io/en/latest/functions/Get-AADGroupByDisplayName
42+
43+
.LINK
44+
http://psmsgraph.readthedocs.io/en/latest/functions/Get-AADGroupMember
45+
4046
.LINK
41-
http://psmsgraph.readthedocs.io/en/latest/functions/Get-AADGroupByDisplayName
47+
http://psmsgraph.readthedocs.io/en/latest/functions/Get-AADGroupByID
4248
#>
4349
function Get-AADGroupByDisplayName {
4450
[CmdletBinding(SupportsShouldProcess = $true,

PSMSGraph/Public/Get-AADGroupById.ps1

+6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
MSGraphAPI.DirectoryObject.Group
3939
.LINK
4040
http://psmsgraph.readthedocs.io/en/latest/functions/Get-AADGroupByID
41+
42+
.LINK
43+
http://psmsgraph.readthedocs.io/en/latest/functions/Get-AADGroupMember
44+
45+
.LINK
46+
http://psmsgraph.readthedocs.io/en/latest/functions/Get-AADGroupByDisplayName
4147
#>
4248
function Get-AADGroupByID {
4349
[CmdletBinding(SupportsShouldProcess = $true,

PSMSGraph/Public/Get-AADGroupMember.ps1

+26-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
===========================================================================
44
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2017 v5.4.135
55
Created on: 2/14/2017 6:02 AM
6+
Edited on: 3/30/2017
67
Created by: Mark Kraus
78
Organization: Mitel
89
Filename: Get-AADGroupMember.ps1
@@ -28,13 +29,31 @@
2829
.PARAMETER APIVersion
2930
version of the API to use. Default is 1.6
3031
32+
.PARAMETER ResultsPerPage
33+
The number of results to request from the API per call. This is the '$top' API query filter. Default is 100. Valid Range is 1-999.
34+
35+
This will not limit the number of resutls retruned by the command.
36+
37+
.OUTPUTS
38+
MSGraphAPI.DirectoryObject.User
39+
40+
.INPUTS
41+
MSGraphAPI.DirectoryObject.Group
42+
3143
.EXAMPLE
3244
PS C:\> $AADGroupMembers = $AADGroup | Get-AADGroupMembers
3345
3446
.NOTES
3547
Additional information about the function.
48+
3649
.LINK
3750
http://psmsgraph.readthedocs.io/en/latest/functions/Get-AADGroupMember
51+
52+
.LINK
53+
http://psmsgraph.readthedocs.io/en/latest/functions/Get-AADGroupByID
54+
55+
.LINK
56+
http://psmsgraph.readthedocs.io/en/latest/functions/Get-AADGroupByDisplayName
3857
#>
3958
function Get-AADGroupMember {
4059
[CmdletBinding(SupportsShouldProcess = $true,
@@ -55,7 +74,11 @@ function Get-AADGroupMember {
5574
[string]$BaseUrl = 'https://graph.windows.net',
5675

5776
[Parameter(ValueFromPipelineByPropertyName = $true)]
58-
[string]$APIVersion = '1.6'
77+
[string]$APIVersion = '1.6',
78+
79+
[Parameter(ValueFromPipelineByPropertyName = $true)]
80+
[ValidateRange(1,999)]
81+
[int]$ResultsPerPage = 100
5982
)
6083

6184
process {
@@ -68,13 +91,14 @@ function Get-AADGroupMember {
6891
$Tenant = $Application.Tenant
6992
$SkipToken = $null
7093
do {
71-
$Url = '{0}/{1}/{2}/{3}/{4}?api-version={5}{6}' -f @(
94+
$Url = '{0}/{1}/{2}/{3}/{4}?api-version={5}{6}{7}' -f @(
7295
$BaseUrl
7396
$Tenant
7497
'groups'
7598
$GroupObject.objectId
7699
'members'
77100
$APIversion
101+
'&$top={0}' -f $ResultsPerPage
78102
$SkipToken
79103
)
80104
$Params = @{

PSMSGraph/Public/Get-GraphOauthAccessToken.ps1

+30-20
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
===========================================================================
44
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2017 v5.4.135
55
Created on: 2/8/2017 10:26 AM
6+
Edited on:: 4/15/2017
67
Created by: Mark Kraus
78
Organization: Mitel
89
Filename: Get-GraphOauthAccessToken.ps1
@@ -33,16 +34,23 @@
3334
3435
You must set the resource to match the endpoints your token will be valid for.
3536
36-
Microsft Graph: https://outlook.office.com
37+
Microsft Graph: https://graph.microsoft.com
3738
Azure AD Graph API: https://graph.windows.net
3839
Office 365 Unified Mail API: https://outlook.office.com
3940
4041
If you need to access more than one resrouce, you will need to request multiple OAuth Access Tokens and use the correct tokens for the correct endpoints.
41-
42-
.PARAMETER ResultVariable
43-
Name of a varibale to store the result from the Invoke-WebRequest. This should be used for debugging only as it stores the access_token and refresh_tokens in memory as plain text.
44-
42+
4543
.EXAMPLE
44+
PS C:\> $ClientCredential = Get-Credential
45+
PS C:\> $Params = @{
46+
Name = 'MyGraphApp'
47+
Description = 'My Graph Application!'
48+
ClientCredential = $ClientCredential
49+
RedirectUri = 'https://adataum/ouath?'
50+
UserAgent = 'Windows:PowerShell:GraphApplication'
51+
}
52+
PS C:\> $GraphApp = New-GraphApplication @Params
53+
PS C:\> $GraphAuthCode = Get-GraphOauthAuthorizationCode -Application $GraphApp
4654
PS C:\> $GraphAccessToken = Get-GraphOauthAccessToken -AuthenticationCode $GraphAuthCode
4755
4856
.OUTPUTS
@@ -87,11 +95,7 @@ function Get-GraphOauthAccessToken {
8795

8896
[Parameter(Mandatory = $false,
8997
ValueFromPipelineByPropertyName = $true)]
90-
[string]$Resource = 'https://graph.microsoft.com',
91-
92-
[Parameter(Mandatory = $false)]
93-
[ValidateNotNullOrEmpty()]
94-
[string]$ResultVariable
98+
[string]$Resource = 'https://graph.microsoft.com'
9599
)
96100

97101
Process {
@@ -105,7 +109,7 @@ function Get-GraphOauthAccessToken {
105109
$AuthCode = [System.Web.HttpUtility]::UrlEncode($AuthenticationCode.GetAuthCode())
106110
$Body = @(
107111
'grant_type=authorization_code'
108-
'&redirect_uri={0}&' -f $Redirect_uri
112+
'&redirect_uri={0}' -f $Redirect_uri
109113
'&client_id={0}' -f $Client_Id
110114
'&code={0}' -f $AuthCode
111115
'&resource={0}' -f $Resource_encoded
@@ -125,25 +129,31 @@ function Get-GraphOauthAccessToken {
125129
try {
126130
Write-Verbose "Retrieving OAuth Access Token from $BaseURL..."
127131
$Result = Invoke-WebRequest @Params
128-
if ($ResultVariable) {
129-
Write-Verbose "Setting result variable '$ResultVariable'"
130-
Set-Variable -Name $ResultVariable -Scope 'Global' -Value $Result
131-
}
132132
}
133133
catch {
134-
$ErrorMessage = $_.Exception.Message
135-
$Message = "Requesting OAuth Access Token Failed: {0} " -f $ErrorMessage
136-
Write-Error -Message $Message
134+
$response = $_.Exception.Response
135+
$Stream = $response.GetResponseStream()
136+
$Stream.Position = 0
137+
$StreamReader = New-Object System.IO.StreamReader $Stream
138+
$ResponseBody = $StreamReader.ReadToEnd()
139+
$ErrorMessage = "Requesting OAuth Access Token from '{0}' Failed: {1}: {2}" -f $BaseURL,
140+
$_.Exception.Message, $ResponseBody
141+
Write-Error -message $ErrorMessage -Exception $_.Exception
137142
return
138143
}
139144
try {
140145
$Content = $Result.Content | ConvertFrom-Json -ErrorAction Stop
141146
}
142147
Catch {
143148
$ErrorMessage = $_.Exception.Message
149+
$Params = @{
150+
MemberType = 'NoteProperty'
151+
Name = 'Respone'
152+
Value = $Result
153+
}
154+
$_.Exception | Add-Member @Params
144155
$Message = "Failed to convert response from JSON: {0}" -f $ErrorMessage
145-
Write-Error $Message
146-
Write-Error $Result.Content
156+
Write-Error -Exception $_.Exception -Message $Message
147157
return
148158
}
149159
$AccessTokenCredential = [pscredential]::new('access_token', $($Content.access_token | ConvertTo-SecureString -AsPlainText -Force))

PSMSGraph/Public/Import-GraphApplication.ps1

+12-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
===========================================================================
44
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2017 v5.4.135
55
Created on: 2/8/2017 8:32 AM
6+
Edited on: 3/30/2017
67
Created by: Mark Kraus
78
Organization: Mitel
89
Filename: Import-GraphApplication.ps1
@@ -79,8 +80,18 @@ function Import-GraphApplication {
7980
if ($pscmdlet.ShouldProcess($ImportFile)) {
8081
$Params = @{
8182
"$ImportParam" = $ImportFile
83+
ErrorAction = 'Stop'
84+
}
85+
try {
86+
$InObject = Import-Clixml @Params
87+
}
88+
catch {
89+
$ErrorMessage = "Unable to import from '{0}': {1}" -f @(
90+
$ImportFile
91+
$_.Exception.Message
92+
)
93+
Write-Error $ErrorMessage
8294
}
83-
$InObject = Import-Clixml @Params
8495
$InObject | New-GraphApplication
8596
} #End Should Process
8697
} #End Foreach

PSMSGraph/Public/Import-GraphOauthAccessToken.ps1

+12-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
===========================================================================
44
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2017 v5.4.135
55
Created on: 2/9/2017 6:55 AM
6+
Edited on: 3/30/2017
67
Created by: Mark Kraus
78
Organization: Mitel
89
Filename: Import-GraphOauthAccessToken.ps1
@@ -77,8 +78,18 @@ function Import-GraphOauthAccessToken {
7778
Write-Verbose "Processing $($ImportFile)."
7879
$Params = @{
7980
"$($PsCmdlet.ParameterSetName)" = $ImportFile
81+
ErrorAction = 'Stop'
82+
}
83+
try {
84+
$InObject = Import-Clixml @Params
85+
}
86+
Catch {
87+
$ErrorMessage = "Unable to import from '{0}': {1}" -f @(
88+
$ImportFile
89+
$_.Exception.Message
90+
)
91+
Write-Error $ErrorMessage
8092
}
81-
$InObject = Import-Clixml @Params
8293
Write-Verbose "Reconstituting Application object"
8394
$Application = $InObject.Application | New-GraphApplication
8495
Write-Verbose 'Reconstituting Session object'

RELEASE.md

+39-36
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,54 @@
1-
# Version 1.0.23.40 (2017-03-05)
21
## Functions
2+
### Import-GraphApplication
3+
* Now provides its own error instead of Import-clixml
34

4-
### All
5-
* Added HelpUri and .LINK's to Comment based Help
6-
7-
### OAuth functions
8-
* Standardized on "Oauth" in the function and file names (was a mix of "OAuth" and "Oath")
5+
### Import-GraphOauthAccessToken
6+
* Now provides its own error instead of Import-clixml
97

108
### Get-AADGroupMember
11-
* Made function singular instead of plural (was Get-AADGroupMembers)
12-
* Added Get-AADGroupMembers alias
13-
* Fixed all the problems this rename caused and exposed with the build process and documentation
9+
* Added ResultsPerPage Paramter to provide access to '$top' query filter.
10+
* Addeed .LINK to Get-AADGroupById
11+
* Addeed .LINK to Get-AADGroupByDisplayName
12+
* Added .INPUTS MSGraphAPI.DirectoryObject.Group
13+
* Added .OUTPUTS MSGraphAPI.DirectoryObject.User
14+
15+
### Get-AADGroupById
16+
* Addeed .LINK to Get-AADGroupByDisplayName
17+
* Addeed .LINK to Get-AADGroupMember
18+
19+
### Get-AADGroupByDisplayName
20+
* Addeed .LINK to Get-AADGroupMember
21+
* Addeed .LINK to Get-AADGroupById
22+
23+
### Get-GraphOauthAccessToken
24+
* **Breaking Change**: Removed ```ResultVariable``` and related debugging code that should never have been in production
25+
* Removed ```ResultVariable``` parameter help
26+
* Improved error reporting
27+
* Fixed ```Resource``` parameter documentation
28+
* Imrpoved Example
29+
* Removed dangling ```&``` from ```$Body``` creation
1430

1531
## Build Tools
16-
1732
### psake.ps1
18-
* Restructured psake.ps1
19-
- Init > UnitTests > Build > Test > BuildDocs > Deploy > Post Deploy
20-
* Added AST based Function and Alias module manifest population (now typos in file names will not cause function export issues)
21-
* Added NestedModule Population
22-
* Added Release notes and change log auto processing and documentation
23-
* PostDeploy is now local build friendly
33+
* Block ```staging``` branch recommits so clean pull requests can be made
34+
* Add ```!skiprecommit``` commit tag to block recommits
2435

2536
## Tests
37+
### Get-AADGroupMember.Unit.Tests.ps1
38+
* Created tests for Get-AADGroupMember
2639

27-
### PSScriptAnalyzer.tests.Ps1
28-
* Moved out of Project.Tests.ps1
29-
* Re-wroded the tests so they display better in AppVeyor test logs
30-
* Removed .psd1 from the tests because it dose not appear to support suppression and certain test will falsely fail due to the text in RealseNotes
31-
32-
### Project.Tests.ps1
33-
* Moved the PSScriptAnalyzer tests to PSScriptAnalyzer.tests.Ps1
34-
* Added Unit tag to "General project validation" so it test before and after build
3540

36-
### New-GraphApplication.Unit.Tests.ps1
37-
* Added Unit test for New-GraphApplication
41+
### Import-GraphApplication.Unit.Tests.ps1
42+
* Created tests for Import-GraphApplication
3843

39-
### New-GraphOauthAccessToken.Unit.Tests.ps1
40-
* Added Unit test for New-GraphOauthAccessToken
44+
### Import-GraphOauthAccessToken.Unit.Tests.ps1
45+
* Created tests for Import-GraphOauthAccessToken
4146

42-
## Project
47+
### Get-AADGroupById.Unit.Tests.ps1
48+
* Created tests for Get-AADGroupById
4349

44-
### RELEASE.md
45-
* Added this to server as the current release notes
46-
* Integrates automatically with ChangeLog.md through build pipeline
47-
* Gets copied to ```docs/```
50+
### Get-AADGroupByDisplayName.Unit.Tests.ps1
51+
* Created tests for Get-AADGroupByDisplayName
4852

49-
### ChangeLog.md
50-
* Added to ```docs/```
51-
* Automatically managed by build process
53+
### Get-GraphOauthAccessToken.Unit.Tests.ps1
54+
* Created tests for Get-GraphOauthAccessToken

0 commit comments

Comments
 (0)