Skip to content

Commit ffae184

Browse files
committed
Added -UseDeviceCode, -TenantId, and -ClientId parameters that are passed to Connect-MgGraph.
1 parent bcf6c50 commit ffae184

File tree

2 files changed

+115
-9
lines changed

2 files changed

+115
-9
lines changed

Graph.EasyPIM/Graph.EasyPIM.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = 'Graph.EasyPIM.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '0.0.10'
15+
ModuleVersion = '0.0.11'
1616

1717
# Supported PSEditions
1818
# CompatiblePSEditions = @()
@@ -118,7 +118,7 @@
118118
# IconUri = ''
119119

120120
# ReleaseNotes of this module
121-
ReleaseNotes = 'Added Disable-PIMGroup. Fixed a bug I introduced in the previous version with Enable-PIMGroup.'
121+
ReleaseNotes = 'Added -UseDeviceCode, -TenantId, and -ClientId parameters that are passed to Connect-MgGraph.'
122122

123123
# Prerelease string of this module
124124
# Prerelease = ''

Graph.EasyPIM/Graph.EasyPIM.psm1

Lines changed: 113 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,15 @@ function Enable-PIMRole {
4646
[Parameter(Mandatory=$false)]
4747
[string]$TicketingSystem,
4848

49-
[switch]$RefreshEligibleRoles
49+
[switch]$RefreshEligibleRoles,
50+
51+
[switch]$UseDeviceCode,
52+
53+
[Parameter(Mandatory=$false)]
54+
[string]$TenantId,
55+
56+
[Parameter(Mandatory=$false)]
57+
[string]$ClientId
5058
)
5159

5260
<#
@@ -67,6 +75,14 @@ function Enable-PIMRole {
6775
.PARAMETER RefreshEligibleRoles
6876
Optional. By default, eligible roles are only checked if it's been more than 30 mins since the last invocation. If you want to check before that, use this switch.
6977
78+
.PARAMETER UseDeviceCode
79+
Optional. Use Device Code authentication.
80+
81+
.PARAMETER TenantId
82+
Optional. Use this TenantId.
83+
84+
.PARAMETER ClientId
85+
Optional. Use this Client Id.
7086
#>
7187

7288
begin {
@@ -80,8 +96,18 @@ function Enable-PIMRole {
8096
Write-Host @colorParams "🎉 A newer version of this module is available in PowerShell Gallery"
8197
}
8298

99+
$graphParams = @{
100+
"Scopes" = $script:requiredScopesArray
101+
"NoWelcome" = $true
102+
"ErrorAction" = "Stop"
103+
}
104+
105+
if ($UseDeviceCode) { $graphParams.UseDeviceCode = $true }
106+
if ($TenantId) { $graphParams.TenantId = $TenantId }
107+
if ($ClientId) { $graphParams.ClientId = $ClientId }
108+
83109
try {
84-
Connect-MgGraph -Scopes $script:requiredScopesArray -NoWelcome -ErrorAction Stop
110+
Connect-MgGraph @graphParams
85111

86112
} catch {
87113
throw "$($_.Exception.Message)"
@@ -558,7 +584,7 @@ function Enable-PIMRole {
558584
$justificationsHash[$($selection.RoleName)] = $justificationInput
559585
}
560586

561-
Write-Host -NoNewline @colorParams ("📋 {0,-$longestRoleLength} | " -f $($selection.GroupName))
587+
Write-Host -NoNewline @colorParams ("📋 {0,-$longestRoleLength} [{1,-$longestScopeLength}] | " -f $($selection.RoleName), $($selection.Scope))
562588
Write-Host "Reason will be set to: $justificationInput"
563589
}
564590
}
@@ -681,6 +707,27 @@ function Enable-PIMRole {
681707
# This is a copy paste of Enable-PIMRole with some bits removed...
682708
# It's very simple compared to Enable-PIMRole
683709
function Disable-PIMRole {
710+
param(
711+
[switch]$UseDeviceCode,
712+
713+
[Parameter(Mandatory=$false)]
714+
[string]$TenantId,
715+
716+
[Parameter(Mandatory=$false)]
717+
[string]$ClientId
718+
)
719+
720+
<#
721+
.PARAMETER UseDeviceCode
722+
Optional. Use Device Code authentication.
723+
724+
.PARAMETER TenantId
725+
Optional. Use this TenantId.
726+
727+
.PARAMETER ClientId
728+
Optional. Use this Client Id.
729+
#>
730+
684731
begin {
685732
Write-Host ""
686733
$colorParams = $script:colorParams
@@ -692,8 +739,18 @@ function Disable-PIMRole {
692739
Write-Host @colorParams "🎉 A newer version of this module is available in PowerShell Gallery"
693740
}
694741

742+
$graphParams = @{
743+
"Scopes" = $script:requiredScopesArray
744+
"NoWelcome" = $true
745+
"ErrorAction" = "Stop"
746+
}
747+
748+
if ($UseDeviceCode) { $graphParams.UseDeviceCode = $true }
749+
if ($TenantId) { $graphParams.TenantId = $TenantId }
750+
if ($ClientId) { $graphParams.ClientId = $ClientId }
751+
695752
try {
696-
Connect-MgGraph -Scopes $script:requiredScopesArray -NoWelcome -ErrorAction Stop
753+
Connect-MgGraph @graphParams
697754

698755
} catch {
699756
throw "$($_.Exception.Message)"
@@ -932,7 +989,15 @@ function Enable-PIMGroup {
932989
[Parameter(Mandatory=$false)]
933990
[string]$TicketingSystem,
934991

935-
[switch]$RefreshEligibleGroups
992+
[switch]$RefreshEligibleGroups,
993+
994+
[switch]$UseDeviceCode,
995+
996+
[Parameter(Mandatory=$false)]
997+
[string]$TenantId,
998+
999+
[Parameter(Mandatory=$false)]
1000+
[string]$ClientId
9361001
)
9371002

9381003
<#
@@ -965,8 +1030,18 @@ function Enable-PIMGroup {
9651030
Write-Host @colorParams "🎉 A newer version of this module is available in PowerShell Gallery"
9661031
}
9671032

1033+
$graphParams = @{
1034+
"Scopes" = $script:requiredScopesArray
1035+
"NoWelcome" = $true
1036+
"ErrorAction" = "Stop"
1037+
}
1038+
1039+
if ($UseDeviceCode) { $graphParams.UseDeviceCode = $true }
1040+
if ($TenantId) { $graphParams.TenantId = $TenantId }
1041+
if ($ClientId) { $graphParams.ClientId = $ClientId }
1042+
9681043
try {
969-
Connect-MgGraph -Scopes $script:requiredScopesArray -NoWelcome -ErrorAction Stop
1044+
Connect-MgGraph @graphParams
9701045

9711046
} catch {
9721047
throw "$($_.Exception.Message)"
@@ -1482,6 +1557,27 @@ function Enable-PIMGroup {
14821557
# This is a copy paste of Enable-PIMRole with some bits removed...
14831558
# It's very simple compared to Enable-PIMRole
14841559
function Disable-PIMGroup {
1560+
param(
1561+
[switch]$UseDeviceCode,
1562+
1563+
[Parameter(Mandatory=$false)]
1564+
[string]$TenantId,
1565+
1566+
[Parameter(Mandatory=$false)]
1567+
[string]$ClientId
1568+
)
1569+
1570+
<#
1571+
.PARAMETER UseDeviceCode
1572+
Optional. Use Device Code authentication.
1573+
1574+
.PARAMETER TenantId
1575+
Optional. Use this TenantId.
1576+
1577+
.PARAMETER ClientId
1578+
Optional. Use this Client Id.
1579+
#>
1580+
14851581
begin {
14861582
Write-Host ""
14871583
$colorParams = $script:colorParams
@@ -1493,8 +1589,18 @@ function Disable-PIMGroup {
14931589
Write-Host @colorParams "🎉 A newer version of this module is available in PowerShell Gallery"
14941590
}
14951591

1592+
$graphParams = @{
1593+
"Scopes" = $script:requiredScopesArray
1594+
"NoWelcome" = $true
1595+
"ErrorAction" = "Stop"
1596+
}
1597+
1598+
if ($UseDeviceCode) { $graphParams.UseDeviceCode = $true }
1599+
if ($TenantId) { $graphParams.TenantId = $TenantId }
1600+
if ($ClientId) { $graphParams.ClientId = $ClientId }
1601+
14961602
try {
1497-
Connect-MgGraph -Scopes $script:requiredScopesArray -NoWelcome -ErrorAction Stop
1603+
Connect-MgGraph @graphParams
14981604

14991605
} catch {
15001606
throw "$($_.Exception.Message)"

0 commit comments

Comments
 (0)