Skip to content

Commit f2fb163

Browse files
Tests refactors, docs creation and cmdlet update to remove prerequisites
1 parent 37c20b5 commit f2fb163

8 files changed

Lines changed: 385 additions & 351 deletions

module/Entra/Microsoft.Entra/Users/Test-EntraBetaCommandPrerequisites.ps1

Lines changed: 0 additions & 145 deletions
This file was deleted.
Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# ------------------------------------------------------------------------------
32
# Copyright (c) Microsoft Corporation. All Rights Reserved.
43
# Licensed under the MIT License. See License in the project root for license information.
@@ -10,88 +9,82 @@ function Update-EntraInvitedUserSponsorsFromInvitedBy {
109
DefaultParameterSetName = 'AllInvitedGuests')]
1110
param (
1211

13-
# UserId of Guest User
14-
[Parameter(ParameterSetName = 'ByUsers')]
12+
# UserId of Guest User
13+
[Parameter(ParameterSetName = 'ByUsers',HelpMessage ="The Unique ID of the User (User ID).")]
1514
[String[]]
1615
$UserId,
1716
# Enumerate and Update All Guest Users.
18-
[Parameter(ParameterSetName = 'AllInvitedGuests')]
17+
[Parameter(ParameterSetName = 'AllInvitedGuests',HelpMessage="A Flag indicating whether to include all invited guests.")]
1918
[switch]
2019
$All
2120
)
2221

23-
begin {
24-
25-
## Initialize Critical Dependencies
26-
$CriticalError = $null
27-
if (!(Test-EntraCommandPrerequisites 'Get-Mguser', 'Update-Mguser' -MinimumVersion 2.8.0 -ErrorVariable CriticalError)) { return }
28-
22+
begin {
2923
$guestFilter = "(CreationType eq 'Invitation')"
3024
}
3125

3226
process {
3327

3428
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand
3529

36-
if ($CriticalError) { return }
3730
if ($null -eq $UserId -and !$All) {
3831
Write-Error "Please specify either -UserId or -All"
3932
return
4033
}
4134

4235
if ($All) {
43-
$InvitedUsers = Get-MgUser -Filter $guestFilter -All -ExpandProperty Sponsors
36+
$invitedUsers = Get-EntraUser -Filter $guestFilter -All -ExpandProperty Sponsors
4437
}
4538
else {
46-
foreach ($user in $userId) {
47-
$InvitedUsers += Get-MgUser -UserId $user -ExpandProperty Sponsors
39+
foreach ($user in $UserId) {
40+
$invitedUsers += Get-EntraUser -UserId $user -ExpandProperty Sponsors
4841
}
4942
}
5043

51-
if ($null -eq $InvitedUsers) {
44+
if ($null -eq $invitedUsers) {
5245
Write-Error "No guest users to process"
5346
}
5447
else {
55-
foreach ($InvitedUser in $InvitedUsers) {
48+
foreach ($invitedUser in $invitedUsers) {
5649
$invitedBy = $null
5750

5851
$splatArgumentsGetInvitedBy = @{
5952
Method = 'Get'
60-
Uri = ((Get-MgEnvironment -Name (Get-MgContext).Environment).GraphEndpoint +
61-
"/v1.0/users/" + $InvitedUser.Id + "/invitedBy")
53+
Uri = ((Get-EntraEnvironment -Name (Get-EntraContext).Environment).GraphEndpoint +
54+
"/v1.0/users/" + $invitedUser.id + "/invitedBy")
6255
}
6356

6457
$invitedBy = Invoke-MgGraphRequest @splatArgumentsGetInvitedBy -Headers $customHeaders
6558

6659
Write-Verbose ($invitedBy | ConvertTo-Json -Depth 10)
6760

6861
if ($null -ne $invitedBy -and $null -ne $invitedBy.value -and $null -ne (Get-ObjectPropertyValue $invitedBy.value -Property 'id')) {
69-
Write-Verbose ("InvitedBy for Guest User {0}: {1}" -f $InvitedUser.DisplayName, $invitedBy.value.id)
62+
Write-Verbose ("InvitedBy for Guest User {0}: {1}" -f $invitedUser.displayName, $invitedBy.value.id)
7063

71-
if (($null -like $InvitedUser.Sponsors) -or ($InvitedUser.Sponsors.id -notcontains $invitedBy.value.id)) {
64+
if (($null -like $invitedUser.sponsors) -or ($invitedUser.sponsors.id -notcontains $invitedBy.value.id)) {
7265
Write-Verbose "Sponsors does not contain the user who invited them!"
7366

74-
if ($PSCmdlet.ShouldProcess(("$($InvitedUser.displayName) ($($InvitedUser.UserPrincipalName) - $($InvitedUser.id))"), "Update Sponsors")) {
67+
if ($PSCmdlet.ShouldProcess(("$($invitedUser.displayName) ($($invitedUser.userPrincipalName) - $($invitedUser.id))"), "Update Sponsors")) {
7568
try {
7669
$sponsorUrl = ("https://graph.microsoft.com/v1.0/users/{0}" -f $invitedBy.value.id)
7770
$dirObj = @{"sponsors@odata.bind" = @($sponsorUrl) }
7871
$sponsorsRequestBody = $dirObj | ConvertTo-Json
7972

80-
Update-MgUser -UserId $InvitedUser.Id -BodyParameter $sponsorsRequestBody -Header $customHeaders
81-
Write-Output "$($InvitedUser.UserPrincipalName) - Sponsor updated succesfully for this user."
73+
Update-EntraUser -UserId $invitedUser.id -BodyParameter $sponsorsRequestBody -Header $customHeaders
74+
Write-Output "$($invitedUser.userPrincipalName) - Sponsor updated successfully for this user."
8275
}
8376
catch {
84-
Write-Output "$($InvitedUser.UserPrincipalName) - Failed updating sponsor for this user."
77+
Write-Output "$($invitedUser.userPrincipalName) - Failed updating sponsor for this user."
8578
Write-Error $_
8679
}
8780
}
8881
}
8982
else {
90-
Write-Output "$($InvitedUser.UserPrincipalName) - Sponsor already exists for this user."
83+
Write-Output "$($invitedUser.userPrincipalName) - Sponsor already exists for this user."
9184
}
9285
}
9386
else {
94-
Write-Output "$($InvitedUser.UserPrincipalName) - Invited user information not available for this user."
87+
Write-Output "$($invitedUser.userPrincipalName) - Invited user information not available for this user."
9588
}
9689
}
9790
}
@@ -101,4 +94,3 @@ function Update-EntraInvitedUserSponsorsFromInvitedBy {
10194
Write-Verbose "Complete!"
10295
}
10396
}
104-

0 commit comments

Comments
 (0)