Skip to content

Commit 27991aa

Browse files
committed
Merge remote-tracking branch 'PSMSGraph-Dev/develop' !deploy
2 parents 340eb51 + 1db6687 commit 27991aa

5 files changed

+127
-45
lines changed

PSMSGraph/Public/Get-AADGroupByDisplayName.ps1

+29-8
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
===========================================================================
44
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2017 v5.4.135
55
Created on: 2/14/2017 5:53 AM
6+
Edited on: 4/22/2017
67
Created by: Mark Kraus
7-
Organization: Mitel
8+
Organization:
89
Filename: Get-AADGroupByDisplayName.ps1
910
===========================================================================
1011
.DESCRIPTION
@@ -13,29 +14,40 @@
1314

1415
<#
1516
.SYNOPSIS
16-
Retrieves an Azure AD Group by the Display name
17+
Retrieves an Azure AD Group by the provided Display name
1718
1819
.DESCRIPTION
19-
Retrieves an Azure AD Group by the Display Name
20+
Searches Azure Active Directory Graph API for a Group by the provided display name.
21+
The provided displayname must be a full case-insensitive match. Partial matches and
22+
wildcards are not supported. A MSGraphAPI.DirectoryObject.Group object will be
23+
returned for the matching group.
24+
25+
Get-AADGroupByDisplayName requires a MSGraphAPI.Oauth.AccessToken issued for the
26+
https://graph.windows.net resource. See the Get-GraphOauthAccessToken help for
27+
more information.
28+
29+
Get-Help -Name Get-GraphOauthAccessToken -Parameter Resource
2030
2131
.PARAMETER AccessToken
2232
MSGraphAPI.Oauth.AccessToken object obtained from Get-GraphOauthAccessToken.
33+
Access Token must be issued for the https://graph.windows.net resource.
2334
2435
.PARAMETER DisplayName
25-
The Group's Display Name. This must be an exact match and does not support wildcards
36+
The Group's Display Name. This must be an exact case-insensitive match and does not
37+
support wildcards or partial matches.
2638
2739
.PARAMETER BaseURL
2840
The Azure AD Graph Base URL. This is not required. Deafult
2941
https://graph.windows.net
3042
3143
.PARAMETER APIVersion
32-
version og the API to use. Default is 1.6
44+
Version of the API to use. Default is 1.6
3345
3446
.EXAMPLE
3547
PS C:\> $AADGroup = Get-AADGroupByDisplayName -AccessToken $GraphAccessToken -DisplayName 'Adataum Finance'
3648
3749
.OUTPUTS
38-
MSGraphAPI.DirectoryObject.ServicePrincipal
50+
MSGraphAPI.DirectoryObject.Group
3951
4052
.LINK
4153
http://psmsgraph.readthedocs.io/en/latest/functions/Get-AADGroupByDisplayName
@@ -45,6 +57,15 @@
4557
4658
.LINK
4759
http://psmsgraph.readthedocs.io/en/latest/functions/Get-AADGroupByID
60+
61+
.LINK
62+
http://psmsgraph.readthedocs.io/en/latest/functions/Get-GraphOauthAccessToken
63+
64+
.LINK
65+
https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/groups-operations
66+
67+
.LINK
68+
https://msdn.microsoft.com/en-us/library/azure/ad/graph/howto/azure-ad-graph-api-supported-queries-filters-and-paging-options#filter
4869
#>
4970
function Get-AADGroupByDisplayName {
5071
[CmdletBinding(SupportsShouldProcess = $true,
@@ -101,8 +122,8 @@ function Get-AADGroupByDisplayName {
101122
$Result = Invoke-GraphRequest @Params
102123
}
103124
catch {
104-
$ErrorMessage = "Unable to query User '{0}': {1}" -f $UserId, $_.Exception.Message
105-
Write-Error $ErrorMessage
125+
$ErrorMessage = "Unable to query Group '{0}': {1}" -f $GroupName, $_.Exception.Message
126+
Write-Error -Message $ErrorMessage -Exception $_.Exception
106127
return
107128
}
108129
foreach ($ServiceObject in $Result.ContentObject.value) {

PSMSGraph/Public/Get-AADGroupById.ps1

+31-8
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,70 @@
33
===========================================================================
44
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2017 v5.4.135
55
Created on: 2/14/2017 6:08 AM
6+
Edited On: 2/23/2017
67
Created by: Mark Kraus
7-
Organization: Mitel
8+
Organization:
89
Filename: Get-AADGroupById.ps1
910
===========================================================================
1011
.DESCRIPTION
11-
A description of the file.
12+
Get-AADGroupById Function
1213
#>
1314

1415
<#
1516
.SYNOPSIS
16-
Retrieves an Azure AD Group by their Object ID
17+
Retrieves an Azure AD Group by hte provided Object ID
1718
1819
.DESCRIPTION
19-
Retrieves an Azure AD Group by their Object ID
20+
Searches Azure Active Directory Graph API for a Group by the provided Object ID.
21+
The provided Object ID must be a full case-insensitive match. Partial matches and
22+
wildcards are not supported. The Object ID is the Azure AD Object ID and not the
23+
ObjectGUID synced from an On-prem AD. A MSGraphAPI.DirectoryObject.Group object will
24+
be returned for the matching group.
25+
26+
Get-AADGroupById requires a MSGraphAPI.Oauth.AccessToken issued for the
27+
https://graph.windows.net resource. See the Get-GraphOauthAccessToken help for
28+
more information.
29+
30+
Get-Help -Name Get-GraphOauthAccessToken -Parameter Resource
2031
2132
.PARAMETER AccessToken
2233
MSGraphAPI.Oauth.AccessToken object obtained from Get-GraphOauthAccessToken.
34+
Access Token must be issued for the https://graph.windows.net resource.
2335
2436
.PARAMETER ObjectId
25-
The group's ObjectID e.g d377e755-9365-400f-ab42-c0bf278c386e
37+
The group's Azure AD ObjectID e.g d377e755-9365-400f-ab42-c0bf278c386e
38+
This is not the ObjectGUID synced from an On-prem AD
2639
2740
.PARAMETER BaseURL
2841
The Azure AD Graph Base URL. This is not required. Deafult
2942
https://graph.windows.net
3043
3144
.PARAMETER APIVersion
32-
version og the API to use. Default is 1.6
45+
Version of the API to use. Default is 1.6
3346
3447
.EXAMPLE
3548
PS C:\> $AADGroup = Get-AADGroupByID -AccessToken $GraphAccessToken -ObjectID d377e755-9365-400f-ab42-c0bf278c386e
3649
3750
.OUTPUTS
3851
MSGraphAPI.DirectoryObject.Group
52+
3953
.LINK
4054
http://psmsgraph.readthedocs.io/en/latest/functions/Get-AADGroupByID
4155
4256
.LINK
4357
http://psmsgraph.readthedocs.io/en/latest/functions/Get-AADGroupMember
4458
4559
.LINK
46-
http://psmsgraph.readthedocs.io/en/latest/functions/Get-AADGroupByDisplayName
60+
http://psmsgraph.readthedocs.io/en/latest/functions/Get-AADGroupByDisplayName
61+
62+
.LINK
63+
http://psmsgraph.readthedocs.io/en/latest/functions/Get-GraphOauthAccessToken
64+
65+
.LINK
66+
https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/groups-operations
67+
68+
.LINK
69+
https://msdn.microsoft.com/en-us/library/azure/ad/graph/howto/azure-ad-graph-api-supported-queries-filters-and-paging-options#filter
4770
#>
4871
function Get-AADGroupByID {
4972
[CmdletBinding(SupportsShouldProcess = $true,
@@ -101,7 +124,7 @@ function Get-AADGroupByID {
101124
}
102125
catch {
103126
$ErrorMessage = "Unable to query Group '{0}': {1}" -f $GroupId, $_.Exception.Message
104-
Write-Error $ErrorMessage
127+
Write-Error -Message $ErrorMessage -Exception $_.Exception
105128
return
106129
}
107130
$OutputObject = $Result.ContentObject.psobject.copy()

RELEASE.md

+33-26
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,39 @@
1-
# Version 1.0.25.42 (2017-04-22)
21
## Functions
3-
### Get-GraphOauthAccessToken
4-
* Revised Invoke-WebRequest error handling. Now uses ```MSGraphAPI.Oauth.Exception``` to handle formating
5-
* Simplified error handling for JSON parsing
6-
* Revamped credential object creation for readbility.
7-
* Clean up debug code
2+
### Get-AADGroupByDisplayName
3+
* Fix error message to say Group instead of uuser and actually put the group name in the error
4+
* ```Write-Error``` now includes original exception with error message
85

9-
## Types
10-
### MSGraphAPI.Oauth.Exception
11-
* Added the ```MSGraphAPI.Oauth.Exception``` type to handle OAuth related ```Invoke-Webrequest``` Exceptions
12-
* New ScriptMethod JSONResponse converts the response stream from the ```Invoke-WebRequest``` exception from JSON to PSObject
6+
### Get-AADGroupById
7+
* ```Write-Error``` now includes original exception with error message
138

14-
## Test
15-
### Get-GraphOauthAccessToken.Unit.Tests.ps1
16-
* Added missing code coverage for ```Invoke-webRequest``` error handling
17-
* Add missing code coverage for JSON parsing error handling
18-
* Now at 100% code coverage for ```Get-GraphOauthAccessToken```!
9+
## Tests
10+
### Get-AADGroupByDisplayName.Unit.Tests.ps1
11+
* Added missing code coverage for ```Invoke-GrapRequest``` error handling
12+
* Now has 100% code coverage for ```Get-AADGroupByDisplayName```
1913

20-
## Built Toolds
21-
### psake.ps1
22-
* Adjust recommit logic in PostDeploy task
23-
* Added ```!forcrecommit``` to override default ignores if needed
24-
* Added ```devlop``` to ignored branch for recommits as constant work in the develop branch leads to staging issues.
25-
* Added comment based help file header.
14+
### Get-AADGroupById.Unit.Tests.ps1
15+
* Added missing code coverage for ```Invoke-GrapRequest``` error handling
16+
* Now has 100% code coverage for ```Get-AADGroupById```
2617

2718
## Documentation
28-
### Get-GraphOauthAccessToken
29-
* Modifyed Description to something useful
30-
* adjusted formating on ```Resource``` parameter
31-
* Added ```Get-GraphOauthAuthorizationCode``` to Notes
32-
* Added ```Get-GraphOauthAuthorizationCode``` to Links
19+
### Get-AADGroupByDisplayName
20+
* Re-worded synopsis
21+
* Add more helpful description
22+
* Added clarity about the required reource for Access Tokens
23+
* Fix typo in ```APIVersion``` parameter
24+
* Corrected Output to reflect the correct object type
25+
* Added the following links:
26+
+ ```Get-GraphOauthAccessToken```
27+
+ MSDN AAD Graph Group Operations
28+
+ MSDN AAD Graph Filter parameter
29+
30+
### Get-AADGroupById
31+
* Re-worded synopsis
32+
* Add more helpful description
33+
* Added clarity about the required reource for Access Tokens
34+
* Added clarity on what ObjectID is required
35+
* Fixed typo in ```APIVersion``` parameter
36+
* Added the following links:
37+
+ ```Get-GraphOauthAccessToken```
38+
+ MSDN AAD Graph Group Operations
39+
+ MSDN AAD Graph Filter parameter

Tests/Get-AADGroupByDisplayName.Unit.Tests.ps1

+17-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
===========================================================================
44
Created with: VSCode
55
Created on: 4/11/2017 04:40 AM
6-
Edited on:
6+
Edited on: 4/22/2017
77
Created by: Mark Kraus
88
Organization:
99
Filename: Get-AADGroupByDisplayName.Unit.Tests.ps1
@@ -70,11 +70,18 @@ $VerifyUrl = @(
7070
'/groups'
7171
'?api-version=1.6'
7272
'&$filter=displayName+eq+%27Marketing%27'
73-
73+
) -Join ''
74+
$VerifyBadUrl = @(
75+
'https://graph.windows.net/'
76+
$AppParams.Tenant
77+
'/groups'
78+
'?api-version=1.6'
79+
'&$filter=displayName+eq+%27BadGroup%27'
7480
) -Join ''
7581

7682
$ValidUrls = @(
7783
$VerifyUrl
84+
$VerifyBadUrl
7885
)
7986
# https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/groups-operations
8087
$Global:AADGroupJSON = @'
@@ -110,6 +117,9 @@ Describe $Command -Tags Unit {
110117
}
111118
return $MockResponse
112119
}
120+
Mock -CommandName Invoke-GraphRequest -ModuleName PSMSGraph -ParameterFilter {$Uri -eq $ValidUrls[1]} -MockWith {
121+
Throw 'invalid group'
122+
}
113123
It 'Does not have errors when passed required parameters' {
114124
$LocalParams = $Params.psobject.Copy()
115125
{ & $Command @LocalParams -ErrorAction Stop } | Should not throw
@@ -134,6 +144,11 @@ Describe $Command -Tags Unit {
134144
$Object = & $Command @LocalParams | Select-Object -First 1
135145
$Object._AccessToken.GUID | should be $Token.GUID
136146
}
147+
It 'Provides friendly errors' {
148+
$LocalParams = $Params.psobject.Copy()
149+
$LocalParams.DisplayName = 'BadGroup'
150+
{ & $Command @LocalParams -ErrorAction Stop } | Should not throw 'Unable to query Group'
151+
}
137152
}
138153

139154
Remove-Variable -Name 'AADGroupJSON' -Scope 'Global'

Tests/Get-AADGroupById.Unit.Tests.ps1

+17-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
===========================================================================
44
Created with: VSCode
55
Created on: 4/11/2017 04:20 AM
6-
Edited on:
6+
Edited on: 4/22/2017
77
Created by: Mark Kraus
88
Organization:
99
Filename: Get-AADGroupById.Unit.Tests.ps1
@@ -71,9 +71,17 @@ $VerifyUrl = @(
7171
'c57cdc98-0dcd-4f90-a82f-c911b288bab9'
7272
'?api-version=1.6'
7373
) -Join ''
74+
$VerifyBadUrl = @(
75+
'https://graph.windows.net/'
76+
$AppParams.Tenant
77+
'/groups/'
78+
'BadGroupId'
79+
'?api-version=1.6'
80+
) -Join ''
7481

7582
$ValidUrls = @(
7683
$VerifyUrl
84+
$VerifyBadUrl
7785
)
7886
# https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/groups-operations
7987
$Global:AADGroupJSON = @'
@@ -109,6 +117,9 @@ Describe $Command -Tags Unit {
109117
}
110118
return $MockResponse
111119
}
120+
Mock -CommandName Invoke-GraphRequest -ModuleName PSMSGraph -ParameterFilter {$Uri -eq $ValidUrls[1]} -MockWith {
121+
Throw 'Invalid Group'
122+
}
112123
It 'Does not have errors when passed required parameters' {
113124
$LocalParams = $Params.psobject.Copy()
114125
{ & $Command @LocalParams -ErrorAction Stop } | Should not throw
@@ -133,6 +144,11 @@ Describe $Command -Tags Unit {
133144
$Object = & $Command @LocalParams | Select-Object -First 1
134145
$Object._AccessToken.GUID | should be $Token.GUID
135146
}
147+
It 'Provides friendly errors' {
148+
$LocalParams = $Params.psobject.Copy()
149+
$LocalParams.ObjectId = 'BadGroupId'
150+
{ & $Command @LocalParams -ErrorAction Stop } | Should not throw 'Unable to query Group'
151+
}
136152
}
137153

138154
Remove-Variable -Name 'AADGroupJSON' -Scope 'Global'

0 commit comments

Comments
 (0)