Skip to content

Commit 70e0b67

Browse files
Adding command prechecks for application resources (#1466)
1 parent 6bdcc18 commit 70e0b67

File tree

190 files changed

+1453
-293
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

190 files changed

+1453
-293
lines changed

module/Entra/Microsoft.Entra/Applications/Add-EntraApplicationOwner.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ function Add-EntraApplicationOwner {
1515
[ValidateNotNullOrEmpty()]
1616
[guid] $OwnerId
1717
)
18+
19+
begin {
20+
# Ensure connection to Microsoft Entra
21+
if (-not (Get-EntraContext)) {
22+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Application.ReadWrite.All' to authenticate."
23+
Write-Error -Message $errorMessage -ErrorAction Stop
24+
return
25+
}
26+
}
27+
1828
PROCESS {
1929
$params = @{}
2030
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand

module/Entra/Microsoft.Entra/Applications/Add-EntraServicePrincipalDelegatedPermissionClassification.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ function Add-EntraServicePrincipalDelegatedPermissionClassification {
2323
[System.String] $PermissionName
2424
)
2525

26+
begin {
27+
# Ensure connection to Microsoft Entra
28+
if (-not (Get-EntraContext)) {
29+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Policy.ReadWrite.PermissionGrant' to authenticate."
30+
Write-Error -Message $errorMessage -ErrorAction Stop
31+
return
32+
}
33+
}
34+
2635
PROCESS {
2736
$params = @{}
2837
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand

module/Entra/Microsoft.Entra/Applications/Add-EntraServicePrincipalOwner.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ function Add-EntraServicePrincipalOwner {
1616
[System.String] $OwnerId
1717
)
1818

19+
begin {
20+
# Ensure connection to Microsoft Entra
21+
if (-not (Get-EntraContext)) {
22+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Application.ReadWrite.All' to authenticate."
23+
Write-Error -Message $errorMessage -ErrorAction Stop
24+
return
25+
}
26+
}
27+
1928
PROCESS {
2029
$params = @{}
2130
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand

module/Entra/Microsoft.Entra/Applications/Get-EntraApplication.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ function Get-EntraApplication {
2828
[System.String[]] $Property
2929
)
3030

31+
begin {
32+
# Ensure connection to Microsoft Entra
33+
if (-not (Get-EntraContext)) {
34+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Application.Read.All' to authenticate."
35+
Write-Error -Message $errorMessage -ErrorAction Stop
36+
return
37+
}
38+
}
39+
3140
PROCESS {
3241
$params = @{}
3342
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand

module/Entra/Microsoft.Entra/Applications/Get-EntraApplicationExtensionProperty.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ function Get-EntraApplicationExtensionProperty {
1515
[System.String[]] $Property
1616
)
1717

18+
begin {
19+
# Ensure connection to Microsoft Entra
20+
if (-not (Get-EntraContext)) {
21+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Application.Read.All' to authenticate."
22+
Write-Error -Message $errorMessage -ErrorAction Stop
23+
return
24+
}
25+
}
26+
1827
PROCESS {
1928
$params = @{}
2029
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand

module/Entra/Microsoft.Entra/Applications/Get-EntraApplicationKeyCredential.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ function Get-EntraApplicationKeyCredential {
1111
[System.String] $ApplicationId
1212
)
1313

14+
begin {
15+
# Ensure connection to Microsoft Entra
16+
if (-not (Get-EntraContext)) {
17+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Application.Read.All' to authenticate."
18+
Write-Error -Message $errorMessage -ErrorAction Stop
19+
return
20+
}
21+
}
22+
1423
PROCESS {
1524
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand
1625
(Get-MgApplication -Headers $customHeaders -ApplicationId $PSBoundParameters["ApplicationId"]).KeyCredentials

module/Entra/Microsoft.Entra/Applications/Get-EntraApplicationLogo.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ function Get-EntraApplicationLogo {
1919
[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Path to save the logo.")]
2020
[System.String] $FilePath
2121
)
22+
23+
begin {
24+
# Ensure connection to Microsoft Entra
25+
if (-not (Get-EntraContext)) {
26+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Application.Read.All' to authenticate."
27+
Write-Error -Message $errorMessage -ErrorAction Stop
28+
return
29+
}
30+
}
31+
2232
PROCESS {
2333
$params = @{}
2434
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand

module/Entra/Microsoft.Entra/Applications/Get-EntraApplicationOwner.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ function Get-EntraApplicationOwner {
2121
[Alias("Select")]
2222
[System.String[]] $Property
2323
)
24+
25+
begin {
26+
# Ensure connection to Microsoft Entra
27+
if (-not (Get-EntraContext)) {
28+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Application.Read.All' to authenticate."
29+
Write-Error -Message $errorMessage -ErrorAction Stop
30+
return
31+
}
32+
}
33+
2434
PROCESS {
2535
$params = @{}
2636
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand

module/Entra/Microsoft.Entra/Applications/Get-EntraApplicationPasswordCredential.ps1

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,33 @@ function Get-EntraApplicationPasswordCredential {
1414
[Alias("Select")]
1515
[System.String[]] $Property
1616
)
17-
$params = @{}
18-
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand
19-
20-
if ($null -ne $PSBoundParameters["Property"]) {
21-
$params["Property"] = $PSBoundParameters["Property"]
17+
begin {
18+
# Ensure connection to Microsoft Entra
19+
if (-not (Get-EntraContext)) {
20+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Application.Read.All' to authenticate."
21+
Write-Error -Message $errorMessage -ErrorAction Stop
22+
return
23+
}
2224
}
2325

24-
# TODO : Invoke API and apply the correct Select query
26+
process {
27+
$params = @{}
28+
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand
2529

26-
$response = (Get-MgApplication -Headers $customHeaders -ApplicationId $PSBoundParameters["ApplicationId"]).PasswordCredentials
30+
if ($null -ne $PSBoundParameters["Property"]) {
31+
$params["Property"] = $PSBoundParameters["Property"]
32+
}
2733

28-
if ($null -ne $PSBoundParameters["Property"]) {
29-
$response | Select-Object $PSBoundParameters["Property"]
30-
}
31-
else {
32-
$response
33-
}
34+
# TODO : Invoke API and apply the correct Select query
35+
36+
$response = (Get-MgApplication -Headers $customHeaders -ApplicationId $PSBoundParameters["ApplicationId"]).PasswordCredentials
37+
38+
if ($null -ne $PSBoundParameters["Property"]) {
39+
$response | Select-Object $PSBoundParameters["Property"]
40+
}
41+
else {
42+
$response
43+
}
44+
}
3445
}
3546

module/Entra/Microsoft.Entra/Applications/Get-EntraApplicationServiceEndpoint.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ function Get-EntraApplicationServiceEndpoint {
2222
[System.String[]] $Property
2323
)
2424

25+
begin {
26+
# Ensure connection to Microsoft Entra
27+
if (-not (Get-EntraContext)) {
28+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Application.Read.All' to authenticate."
29+
Write-Error -Message $errorMessage -ErrorAction Stop
30+
return
31+
}
32+
}
33+
2534
PROCESS {
2635
$params = @{}
2736
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand

module/Entra/Microsoft.Entra/Applications/Get-EntraApplicationTemplate.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ function Get-EntraApplicationTemplate {
2323
[System.String[]] $Property
2424
)
2525

26+
begin {
27+
# Ensure connection to Microsoft Entra
28+
if (-not (Get-EntraContext)) {
29+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Application.Read.All' to authenticate."
30+
Write-Error -Message $errorMessage -ErrorAction Stop
31+
return
32+
}
33+
}
34+
2635
PROCESS {
2736
$params = @{}
2837
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand

module/Entra/Microsoft.Entra/Applications/Get-EntraDeletedApplication.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ function Get-EntraDeletedApplication {
2727
[System.String[]] $Property
2828
)
2929

30+
begin {
31+
# Ensure connection to Microsoft Entra
32+
if (-not (Get-EntraContext)) {
33+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Application.Read.All' to authenticate."
34+
Write-Error -Message $errorMessage -ErrorAction Stop
35+
return
36+
}
37+
}
38+
3039
PROCESS {
3140
$params = @{}
3241
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand

module/Entra/Microsoft.Entra/Applications/Get-EntraDeletedServicePrincipal.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ function Get-EntraDeletedServicePrincipal {
2828
[System.String[]] $Property
2929
)
3030

31+
begin {
32+
# Ensure connection to Microsoft Entra
33+
if (-not (Get-EntraContext)) {
34+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Application.Read.All' to authenticate."
35+
Write-Error -Message $errorMessage -ErrorAction Stop
36+
return
37+
}
38+
}
39+
3140
PROCESS {
3241
$params = @{}
3342
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand

module/Entra/Microsoft.Entra/Applications/Get-EntraServicePrincipal.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ function Get-EntraServicePrincipal {
2828
[System.String[]] $Property
2929
)
3030

31+
begin {
32+
# Ensure connection to Microsoft Entra
33+
if (-not (Get-EntraContext)) {
34+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Application.Read.All' to authenticate."
35+
Write-Error -Message $errorMessage -ErrorAction Stop
36+
return
37+
}
38+
}
39+
3140
PROCESS {
3241
$params = @{}
3342
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand

module/Entra/Microsoft.Entra/Applications/Get-EntraServicePrincipalAppRoleAssignedTo.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ function Get-EntraServicePrincipalAppRoleAssignedTo {
2222
[System.String[]] $Property
2323
)
2424

25+
begin {
26+
# Ensure connection to Microsoft Entra
27+
if (-not (Get-EntraContext)) {
28+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Application.Read.All' to authenticate."
29+
Write-Error -Message $errorMessage -ErrorAction Stop
30+
return
31+
}
32+
}
33+
2534
PROCESS {
2635
$params = @{}
2736
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand

module/Entra/Microsoft.Entra/Applications/Get-EntraServicePrincipalAppRoleAssignment.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ function Get-EntraServicePrincipalAppRoleAssignment {
2323
[System.String[]] $Property
2424
)
2525

26+
begin {
27+
# Ensure connection to Microsoft Entra
28+
if (-not (Get-EntraContext)) {
29+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Application.Read.All' to authenticate."
30+
Write-Error -Message $errorMessage -ErrorAction Stop
31+
return
32+
}
33+
}
34+
2635
PROCESS {
2736
$params = @{}
2837
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand

module/Entra/Microsoft.Entra/Applications/Get-EntraServicePrincipalCreatedObject.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ function Get-EntraServicePrincipalCreatedObject {
2323
[System.String[]] $Property
2424
)
2525

26+
begin {
27+
# Ensure connection to Microsoft Entra
28+
if (-not (Get-EntraContext)) {
29+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Application.Read.All' to authenticate."
30+
Write-Error -Message $errorMessage -ErrorAction Stop
31+
return
32+
}
33+
}
34+
2635
PROCESS {
2736
$params = @{}
2837
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand

module/Entra/Microsoft.Entra/Applications/Get-EntraServicePrincipalDelegatedPermissionClassification.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ function Get-EntraServicePrincipalDelegatedPermissionClassification {
2222
[System.String[]] $Property
2323
)
2424

25+
begin {
26+
# Ensure connection to Microsoft Entra
27+
if (-not (Get-EntraContext)) {
28+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Application.Read.All' to authenticate."
29+
Write-Error -Message $errorMessage -ErrorAction Stop
30+
return
31+
}
32+
}
33+
2534
PROCESS {
2635
$params = @{}
2736
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand

module/Entra/Microsoft.Entra/Applications/Get-EntraServicePrincipalKeyCredential.ps1

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,27 @@ function Get-EntraServicePrincipalKeyCredential {
1111
[System.String] $ServicePrincipalId
1212
)
1313

14-
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand
15-
$response = (Get-MgServicePrincipal -Headers $customHeaders -ServicePrincipalId $PSBoundParameters["ServicePrincipalId"]).KeyCredentials
16-
$response | ForEach-Object {
17-
if ($null -ne $_) {
18-
Add-Member -InputObject $_ -MemberType AliasProperty -Name StartDate -Value StartDateTime
19-
Add-Member -InputObject $_ -MemberType AliasProperty -Name EndDate -Value EndDateTime
14+
begin {
15+
# Ensure connection to Microsoft Entra
16+
if (-not (Get-EntraContext)) {
17+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Application.Read.All' to authenticate."
18+
Write-Error -Message $errorMessage -ErrorAction Stop
19+
return
2020
}
2121
}
22-
$response
22+
23+
process {
24+
25+
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand
26+
$response = (Get-MgServicePrincipal -Headers $customHeaders -ServicePrincipalId $PSBoundParameters["ServicePrincipalId"]).KeyCredentials
27+
$response | ForEach-Object {
28+
if ($null -ne $_) {
29+
Add-Member -InputObject $_ -MemberType AliasProperty -Name StartDate -Value StartDateTime
30+
Add-Member -InputObject $_ -MemberType AliasProperty -Name EndDate -Value EndDateTime
31+
}
32+
}
33+
$response
34+
35+
}
2336
}
2437

module/Entra/Microsoft.Entra/Applications/Get-EntraServicePrincipalMembership.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ function Get-EntraServicePrincipalMembership {
2121
[System.String[]] $Property
2222
)
2323

24+
begin {
25+
# Ensure connection to Microsoft Entra
26+
if (-not (Get-EntraContext)) {
27+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Application.Read.All' to authenticate."
28+
Write-Error -Message $errorMessage -ErrorAction Stop
29+
return
30+
}
31+
}
32+
2433
PROCESS {
2534
$params = @{}
2635
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand

module/Entra/Microsoft.Entra/Applications/Get-EntraServicePrincipalOAuth2PermissionGrant.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ function Get-EntraServicePrincipalOAuth2PermissionGrant {
2323
[System.String[]] $Property
2424
)
2525

26+
begin {
27+
# Ensure connection to Microsoft Entra
28+
if (-not (Get-EntraContext)) {
29+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Directory.Read.All' to authenticate."
30+
Write-Error -Message $errorMessage -ErrorAction Stop
31+
return
32+
}
33+
}
34+
2635
PROCESS {
2736
$params = @{}
2837
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand

0 commit comments

Comments
 (0)