From e9a6e819e9c3c30418591c89fdb83078063adc10 Mon Sep 17 00:00:00 2001 From: Steve Mutungi <132555836+SteveMutungi254@users.noreply.github.com> Date: Mon, 25 Nov 2024 17:07:38 +0300 Subject: [PATCH 01/12] Adding code --- .../Get-EntraDeletedServicePrincipal.ps1 | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 module/Entra/AdditionalFunctions/Get-EntraDeletedServicePrincipal.ps1 diff --git a/module/Entra/AdditionalFunctions/Get-EntraDeletedServicePrincipal.ps1 b/module/Entra/AdditionalFunctions/Get-EntraDeletedServicePrincipal.ps1 new file mode 100644 index 0000000000..65e95d2db5 --- /dev/null +++ b/module/Entra/AdditionalFunctions/Get-EntraDeletedServicePrincipal.ps1 @@ -0,0 +1,112 @@ +# ------------------------------------------------------------------------------ +# Copyright (c) Microsoft Corporation. All Rights Reserved. +# Licensed under the MIT License. See License in the project root for license information. +# ------------------------------------------------------------------------------ + +function Get-EntraDeletedServicePrincipal { + [CmdletBinding(DefaultParameterSetName = 'GetQuery')] + param ( + [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Filter to apply to the query.")] + [System.String] $Filter, + + [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Retrieve all deleted service principals.")] + [switch] $All, + + [Parameter(ParameterSetName = "GetVague", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Search string to use for vague queries.")] + [System.String] $SearchString, + + [Alias('Id')] + [Parameter(ParameterSetName = "GetById", Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Service Principal ID to retrieve.")] + [System.String] $ServicePrincipalId, + + [Alias('Limit')] + [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Maximum number of results to return.")] + [System.Nullable`1[System.Int32]] $Top, + + [Alias('Select')] + [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")] + [System.String[]] $Property + ) + + PROCESS { + $params = @{} + $customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand + $keysChanged = @{ SearchString = "Filter" } + + if ($null -ne $PSBoundParameters["ErrorAction"]) { + $params["ErrorAction"] = $PSBoundParameters["ErrorAction"] + } + if ($null -ne $PSBoundParameters["ServicePrincipalId"]) { + $params["DirectoryObjectId"] = $PSBoundParameters["ServicePrincipalId"] + } + if ($PSBoundParameters.ContainsKey("Verbose")) { + $params["Verbose"] = $PSBoundParameters["Verbose"] + } + if ($null -ne $PSBoundParameters["OutVariable"]) { + $params["OutVariable"] = $PSBoundParameters["OutVariable"] + } + if ($null -ne $PSBoundParameters["InformationAction"]) { + $params["InformationAction"] = $PSBoundParameters["InformationAction"] + } + if ($null -ne $PSBoundParameters["WarningVariable"]) { + $params["WarningVariable"] = $PSBoundParameters["WarningVariable"] + } + if ($PSBoundParameters.ContainsKey("Debug")) { + $params["Debug"] = $PSBoundParameters["Debug"] + } + if ($null -ne $PSBoundParameters["PipelineVariable"]) { + $params["PipelineVariable"] = $PSBoundParameters["PipelineVariable"] + } + if ($null -ne $PSBoundParameters["SearchString"]) { + $TmpValue = $PSBoundParameters["SearchString"] + $Value = "displayName eq '$TmpValue' or startswith(displayName,'$TmpValue')" + $params["Filter"] = $Value + } + if ($null -ne $PSBoundParameters["ErrorVariable"]) { + $params["ErrorVariable"] = $PSBoundParameters["ErrorVariable"] + } + if ($null -ne $PSBoundParameters["Top"]) { + $params["Top"] = $PSBoundParameters["Top"] + } + if ($null -ne $PSBoundParameters["OutBuffer"]) { + $params["OutBuffer"] = $PSBoundParameters["OutBuffer"] + } + if ($null -ne $PSBoundParameters["All"]) { + if ($PSBoundParameters["All"]) { + $params["All"] = $PSBoundParameters["All"] + } + } + if ($null -ne $PSBoundParameters["WarningAction"]) { + $params["WarningAction"] = $PSBoundParameters["WarningAction"] + } + if ($null -ne $PSBoundParameters["Filter"]) { + $TmpValue = $PSBoundParameters["Filter"] + foreach ($i in $keysChanged.GetEnumerator()) { + $TmpValue = $TmpValue.Replace($i.Key, $i.Value) + } + $Value = $TmpValue + $params["Filter"] = $Value + } + if ($null -ne $PSBoundParameters["InformationVariable"]) { + $params["InformationVariable"] = $PSBoundParameters["InformationVariable"] + } + if ($null -ne $PSBoundParameters["Property"]) { + $params["Property"] = $PSBoundParameters["Property"] + } + + # Debug logging for transformations + Write-Debug "============================ TRANSFORMATIONS ============================" + $params.Keys | ForEach-Object { "$_ : $($params[$_])" } | Write-Debug + Write-Debug "=========================================================================`n" + + try { + # Make the API call + $response = Get-MgDirectoryDeletedItemAsServicePrincipal @params -Headers $customHeaders + return $response + } + catch { + # Handle any errors that occur during the API call + Write-Error "An error occurred while retrieving the deleted administrative units: $_" + } + } +} \ No newline at end of file From c3472ec62d8561048ed750b395fd95d0fd63079e Mon Sep 17 00:00:00 2001 From: Steve Mutungi <132555836+SteveMutungi254@users.noreply.github.com> Date: Mon, 25 Nov 2024 17:10:22 +0300 Subject: [PATCH 02/12] Updating error message --- .../AdditionalFunctions/Get-EntraDeletedServicePrincipal.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/Entra/AdditionalFunctions/Get-EntraDeletedServicePrincipal.ps1 b/module/Entra/AdditionalFunctions/Get-EntraDeletedServicePrincipal.ps1 index 65e95d2db5..c0e52ccab2 100644 --- a/module/Entra/AdditionalFunctions/Get-EntraDeletedServicePrincipal.ps1 +++ b/module/Entra/AdditionalFunctions/Get-EntraDeletedServicePrincipal.ps1 @@ -106,7 +106,7 @@ function Get-EntraDeletedServicePrincipal { } catch { # Handle any errors that occur during the API call - Write-Error "An error occurred while retrieving the deleted administrative units: $_" + Write-Error "An error occurred while retrieving the deleted service principals: $_" } } } \ No newline at end of file From eb9396c8c47b2a3eeaa0359053c07de2bbc1693d Mon Sep 17 00:00:00 2001 From: Steve Mutungi <132555836+SteveMutungi254@users.noreply.github.com> Date: Mon, 25 Nov 2024 17:15:38 +0300 Subject: [PATCH 03/12] Formatting outputs --- .../Get-EntraDeletedServicePrincipal.ps1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/module/Entra/AdditionalFunctions/Get-EntraDeletedServicePrincipal.ps1 b/module/Entra/AdditionalFunctions/Get-EntraDeletedServicePrincipal.ps1 index c0e52ccab2..12d7021315 100644 --- a/module/Entra/AdditionalFunctions/Get-EntraDeletedServicePrincipal.ps1 +++ b/module/Entra/AdditionalFunctions/Get-EntraDeletedServicePrincipal.ps1 @@ -102,7 +102,11 @@ function Get-EntraDeletedServicePrincipal { try { # Make the API call $response = Get-MgDirectoryDeletedItemAsServicePrincipal @params -Headers $customHeaders - return $response + + # Process the response if needed + $processedResponse = $response | Select-Object -Property Id, DisplayName, DeletedDateTime, @{Name = "PermanentDeletionDate"; Expression = { $_.DeletedDateTime.AddDays(30) } } + + return $processedResponse } catch { # Handle any errors that occur during the API call From a47033dd752cfecf6cb5020a9fd27d2f73c83f5c Mon Sep 17 00:00:00 2001 From: Steve Mutungi <132555836+SteveMutungi254@users.noreply.github.com> Date: Mon, 25 Nov 2024 17:18:15 +0300 Subject: [PATCH 04/12] Reverting formatting --- .../Get-EntraDeletedServicePrincipal.ps1 | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/module/Entra/AdditionalFunctions/Get-EntraDeletedServicePrincipal.ps1 b/module/Entra/AdditionalFunctions/Get-EntraDeletedServicePrincipal.ps1 index 12d7021315..8c7ee7186c 100644 --- a/module/Entra/AdditionalFunctions/Get-EntraDeletedServicePrincipal.ps1 +++ b/module/Entra/AdditionalFunctions/Get-EntraDeletedServicePrincipal.ps1 @@ -101,12 +101,9 @@ function Get-EntraDeletedServicePrincipal { try { # Make the API call - $response = Get-MgDirectoryDeletedItemAsServicePrincipal @params -Headers $customHeaders - - # Process the response if needed - $processedResponse = $response | Select-Object -Property Id, DisplayName, DeletedDateTime, @{Name = "PermanentDeletionDate"; Expression = { $_.DeletedDateTime.AddDays(30) } } - - return $processedResponse + $response = Get-MgDirectoryDeletedItemAsServicePrincipal @params -Headers $customHeaders + + return $response } catch { # Handle any errors that occur during the API call From 42571a3adddc5ada039d13b8cc1d5852cbd734e9 Mon Sep 17 00:00:00 2001 From: Steve Mutungi <132555836+SteveMutungi254@users.noreply.github.com> Date: Mon, 25 Nov 2024 17:44:40 +0300 Subject: [PATCH 05/12] Beta command logic --- .../Get-EntraBetaDeletedServicePrincipal.ps1 | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 module/EntraBeta/AdditionalFunctions/Get-EntraBetaDeletedServicePrincipal.ps1 diff --git a/module/EntraBeta/AdditionalFunctions/Get-EntraBetaDeletedServicePrincipal.ps1 b/module/EntraBeta/AdditionalFunctions/Get-EntraBetaDeletedServicePrincipal.ps1 new file mode 100644 index 0000000000..659f6b78f2 --- /dev/null +++ b/module/EntraBeta/AdditionalFunctions/Get-EntraBetaDeletedServicePrincipal.ps1 @@ -0,0 +1,113 @@ +# ------------------------------------------------------------------------------ +# Copyright (c) Microsoft Corporation. All Rights Reserved. +# Licensed under the MIT License. See License in the project root for license information. +# ------------------------------------------------------------------------------ + +function Get-EntraBetaDeletedServicePrincipal { + [CmdletBinding(DefaultParameterSetName = 'GetQuery')] + param ( + [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Filter to apply to the query.")] + [System.String] $Filter, + + [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Retrieve all deleted service principals.")] + [switch] $All, + + [Parameter(ParameterSetName = "GetVague", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Search string to use for vague queries.")] + [System.String] $SearchString, + + [Alias('Id')] + [Parameter(ParameterSetName = "GetById", Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Service Principal ID to retrieve.")] + [System.String] $ServicePrincipalId, + + [Alias('Limit')] + [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Maximum number of results to return.")] + [System.Nullable`1[System.Int32]] $Top, + + [Alias('Select')] + [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")] + [System.String[]] $Property + ) + + PROCESS { + $params = @{} + $customHeaders = New-EntraBetaCustomHeaders -Command $MyInvocation.MyCommand + $keysChanged = @{ SearchString = "Filter" } + + if ($null -ne $PSBoundParameters["ErrorAction"]) { + $params["ErrorAction"] = $PSBoundParameters["ErrorAction"] + } + if ($null -ne $PSBoundParameters["ServicePrincipalId"]) { + $params["DirectoryObjectId"] = $PSBoundParameters["ServicePrincipalId"] + } + if ($PSBoundParameters.ContainsKey("Verbose")) { + $params["Verbose"] = $PSBoundParameters["Verbose"] + } + if ($null -ne $PSBoundParameters["OutVariable"]) { + $params["OutVariable"] = $PSBoundParameters["OutVariable"] + } + if ($null -ne $PSBoundParameters["InformationAction"]) { + $params["InformationAction"] = $PSBoundParameters["InformationAction"] + } + if ($null -ne $PSBoundParameters["WarningVariable"]) { + $params["WarningVariable"] = $PSBoundParameters["WarningVariable"] + } + if ($PSBoundParameters.ContainsKey("Debug")) { + $params["Debug"] = $PSBoundParameters["Debug"] + } + if ($null -ne $PSBoundParameters["PipelineVariable"]) { + $params["PipelineVariable"] = $PSBoundParameters["PipelineVariable"] + } + if ($null -ne $PSBoundParameters["SearchString"]) { + $TmpValue = $PSBoundParameters["SearchString"] + $Value = "displayName eq '$TmpValue' or startswith(displayName,'$TmpValue')" + $params["Filter"] = $Value + } + if ($null -ne $PSBoundParameters["ErrorVariable"]) { + $params["ErrorVariable"] = $PSBoundParameters["ErrorVariable"] + } + if ($null -ne $PSBoundParameters["Top"]) { + $params["Top"] = $PSBoundParameters["Top"] + } + if ($null -ne $PSBoundParameters["OutBuffer"]) { + $params["OutBuffer"] = $PSBoundParameters["OutBuffer"] + } + if ($null -ne $PSBoundParameters["All"]) { + if ($PSBoundParameters["All"]) { + $params["All"] = $PSBoundParameters["All"] + } + } + if ($null -ne $PSBoundParameters["WarningAction"]) { + $params["WarningAction"] = $PSBoundParameters["WarningAction"] + } + if ($null -ne $PSBoundParameters["Filter"]) { + $TmpValue = $PSBoundParameters["Filter"] + foreach ($i in $keysChanged.GetEnumerator()) { + $TmpValue = $TmpValue.Replace($i.Key, $i.Value) + } + $Value = $TmpValue + $params["Filter"] = $Value + } + if ($null -ne $PSBoundParameters["InformationVariable"]) { + $params["InformationVariable"] = $PSBoundParameters["InformationVariable"] + } + if ($null -ne $PSBoundParameters["Property"]) { + $params["Property"] = $PSBoundParameters["Property"] + } + + # Debug logging for transformations + Write-Debug "============================ TRANSFORMATIONS ============================" + $params.Keys | ForEach-Object { "$_ : $($params[$_])" } | Write-Debug + Write-Debug "=========================================================================`n" + + try { + # Make the API call + $response = Get-MgBetaDirectoryDeletedItemAsServicePrincipal @params -Headers $customHeaders + + return $response + } + catch { + # Handle any errors that occur during the API call + Write-Error "An error occurred while retrieving the deleted service principals: $_" + } + } +} \ No newline at end of file From 87559b5d38e5fdab83a5266d5e2c2c5a772bdaf8 Mon Sep 17 00:00:00 2001 From: Steve Mutungi <132555836+SteveMutungi254@users.noreply.github.com> Date: Mon, 25 Nov 2024 17:54:40 +0300 Subject: [PATCH 06/12] Adding unit test --- ...Get-EntraDeletedServicePrincipal.Tests.ps1 | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 test/module/Entra/Get-EntraDeletedServicePrincipal.Tests.ps1 diff --git a/test/module/Entra/Get-EntraDeletedServicePrincipal.Tests.ps1 b/test/module/Entra/Get-EntraDeletedServicePrincipal.Tests.ps1 new file mode 100644 index 0000000000..f50220ec4e --- /dev/null +++ b/test/module/Entra/Get-EntraDeletedServicePrincipal.Tests.ps1 @@ -0,0 +1,91 @@ +# ------------------------------------------------------------------------------ +# Copyright (c) Microsoft Corporation. All Rights Reserved. +# Licensed under the MIT License. See License in the project root for license information. +# ------------------------------------------------------------------------------ + +BeforeAll { + if ((Get-Module -Name Microsoft.Graph.Entra) -eq $null) { + Import-Module Microsoft.Graph.Entra + } + Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force + + $scriptblock = { + return @( + [PSCustomObject]@{ + "DisplayName" = "Contoso Marketing" + "Id" = "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" + "AppId" = "00001111-aaaa-2222-bbbb-3333cccc4444" + "ServicePrincipalType" = "Application" + } + ) + } + + Mock -CommandName Get-MgDirectoryDeletedItemAsServicePrincipal -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} + +Describe "Get-EntraDeletedServicePrincipal" { + Context "Test for Get-EntraDeletedServicePrincipal" { + It "Should return all service principals" { + $result = Get-EntraDeletedServicePrincipal + $result | Should -Not -BeNullOrEmpty + Should -Invoke -CommandName Get-MgDirectoryDeletedItemAsServicePrincipal -ModuleName Microsoft.Graph.Entra -Times 1 + } + + It "Should return specific service principal by searchstring" { + $result = Get-EntraDeletedServicePrincipal -SearchString 'Contoso Marketing' + $result | Should -Not -BeNullOrEmpty + $result.DisplayName | Should -Be 'Contoso Marketing' + Should -Invoke -CommandName Get-MgDirectoryDeletedItemAsServicePrincipal -ModuleName Microsoft.Graph.Entra -Times 1 + } + + It "Should return specific service principal by filter" { + $result = Get-EntraDeletedServicePrincipal -Filter "DisplayName -eq 'Contoso Marketing'" + $result | Should -Not -BeNullOrEmpty + $result.DisplayName | Should -Be 'Contoso Marketing' + Should -Invoke -CommandName Get-MgDirectoryDeletedItemAsServicePrincipal -ModuleName Microsoft.Graph.Entra -Times 1 + } + + It "Should return top service principal" { + $result = Get-EntraDeletedServicePrincipal -Top 1 + $result | Should -Not -BeNullOrEmpty + Should -Invoke -CommandName Get-MgDirectoryDeletedItemAsServicePrincipal -ModuleName Microsoft.Graph.Entra -Times 1 + } + + It "Property parameter should work" { + $result = Get-EntraDeletedServicePrincipal -Property "DisplayName" + $result | Should -Not -BeNullOrEmpty + $result.DisplayName | Should -Be "Contoso Marketing" + Should -Invoke -CommandName Get-MgDirectoryDeletedItemAsServicePrincipal -ModuleName Microsoft.Graph.Entra -Times 1 + } + + It "Should fail when Property is empty" { + { Get-EntraDeletedServicePrincipal -Property } | Should -Throw "Missing an argument for parameter 'Property'*" + } + + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraDeletedServicePrincipal" + $result = Get-EntraDeletedServicePrincipal -Filter "DisplayName -eq 'Contoso Marketing'" + $result | Should -Not -BeNullOrEmpty + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraDeletedServicePrincipal" + Should -Invoke -CommandName Get-MgDirectoryDeletedItemAsServicePrincipal -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter { + $Headers.'User-Agent' | Should -Be $userAgentHeaderValue + $true + } + } + + It "Should execute successfully without throwing an error" { + # Disable confirmation prompts + $originalDebugPreference = $DebugPreference + $DebugPreference = 'Continue' + + try { + # Act & Assert: Ensure the function doesn't throw an exception + { Get-EntraDeletedServicePrincipal -Debug } | Should -Not -Throw + } + finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } + } +} \ No newline at end of file From 71f0be831d407f91c06a4760ef986f9b2d24b454 Mon Sep 17 00:00:00 2001 From: Steve Mutungi <132555836+SteveMutungi254@users.noreply.github.com> Date: Mon, 25 Nov 2024 17:58:02 +0300 Subject: [PATCH 07/12] Adding Beta Unit tests --- ...EntraBetaDeletedServicePrincipal.Tests.ps1 | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 test/module/EntraBeta/Get-EntraBetaDeletedServicePrincipal.Tests.ps1 diff --git a/test/module/EntraBeta/Get-EntraBetaDeletedServicePrincipal.Tests.ps1 b/test/module/EntraBeta/Get-EntraBetaDeletedServicePrincipal.Tests.ps1 new file mode 100644 index 0000000000..4284bc1def --- /dev/null +++ b/test/module/EntraBeta/Get-EntraBetaDeletedServicePrincipal.Tests.ps1 @@ -0,0 +1,91 @@ +# ------------------------------------------------------------------------------ +# Copyright (c) Microsoft Corporation. All Rights Reserved. +# Licensed under the MIT License. See License in the project root for license information. +# ------------------------------------------------------------------------------ + +BeforeAll { + if ((Get-Module -Name Microsoft.Graph.Entra.Beta) -eq $null) { + Import-Module Microsoft.Graph.Entra.Beta + } + Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force + + $scriptblock = { + return @( + [PSCustomObject]@{ + "DisplayName" = "Contoso Marketing" + "Id" = "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" + "AppId" = "00001111-aaaa-2222-bbbb-3333cccc4444" + "ServicePrincipalType" = "Application" + } + ) + } + + Mock -CommandName Get-MgBetaDirectoryDeletedItemAsServicePrincipal -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra.Beta +} + +Describe "Get-EntraBetaDeletedServicePrincipal" { + Context "Test for Get-EntraBetaDeletedServicePrincipal" { + It "Should return all service principals" { + $result = Get-EntraBetaDeletedServicePrincipal + $result | Should -Not -BeNullOrEmpty + Should -Invoke -CommandName Get-MgBetaDirectoryDeletedItemAsServicePrincipal -ModuleName Microsoft.Graph.Entra.Beta -Times 1 + } + + It "Should return specific service principal by searchstring" { + $result = Get-EntraBetaDeletedServicePrincipal -SearchString 'Contoso Marketing' + $result | Should -Not -BeNullOrEmpty + $result.DisplayName | Should -Be 'Contoso Marketing' + Should -Invoke -CommandName Get-MgBetaDirectoryDeletedItemAsServicePrincipal -ModuleName Microsoft.Graph.Entra.Beta -Times 1 + } + + It "Should return specific service principal by filter" { + $result = Get-EntraBetaDeletedServicePrincipal -Filter "DisplayName -eq 'Contoso Marketing'" + $result | Should -Not -BeNullOrEmpty + $result.DisplayName | Should -Be 'Contoso Marketing' + Should -Invoke -CommandName Get-MgBetaDirectoryDeletedItemAsServicePrincipal -ModuleName Microsoft.Graph.Entra.Beta -Times 1 + } + + It "Should return top service principal" { + $result = Get-EntraBetaDeletedServicePrincipal -Top 1 + $result | Should -Not -BeNullOrEmpty + Should -Invoke -CommandName Get-MgBetaDirectoryDeletedItemAsServicePrincipal -ModuleName Microsoft.Graph.Entra.Beta -Times 1 + } + + It "Property parameter should work" { + $result = Get-EntraBetaDeletedServicePrincipal -Property "DisplayName" + $result | Should -Not -BeNullOrEmpty + $result.DisplayName | Should -Be "Contoso Marketing" + Should -Invoke -CommandName Get-MgBetaDirectoryDeletedItemAsServicePrincipal -ModuleName Microsoft.Graph.Entra.Beta -Times 1 + } + + It "Should fail when Property is empty" { + { Get-EntraBetaDeletedServicePrincipal -Property } | Should -Throw "Missing an argument for parameter 'Property'*" + } + + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraBetaDeletedServicePrincipal" + $result = Get-EntraBetaDeletedServicePrincipal -Filter "DisplayName -eq 'Contoso Marketing'" + $result | Should -Not -BeNullOrEmpty + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraBetaDeletedServicePrincipal" + Should -Invoke -CommandName Get-MgBetaDirectoryDeletedItemAsServicePrincipal -ModuleName Microsoft.Graph.Entra.Beta -Times 1 -ParameterFilter { + $Headers.'User-Agent' | Should -Be $userAgentHeaderValue + $true + } + } + + It "Should execute successfully without throwing an error" { + # Disable confirmation prompts + $originalDebugPreference = $DebugPreference + $DebugPreference = 'Continue' + + try { + # Act & Assert: Ensure the function doesn't throw an exception + { Get-EntraBetaDeletedServicePrincipal -Debug } | Should -Not -Throw + } + finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } + } +} \ No newline at end of file From b8a1e8b05b6caedd2f23af146b9900eaae6fb2d3 Mon Sep 17 00:00:00 2001 From: Steve Mutungi <132555836+SteveMutungi254@users.noreply.github.com> Date: Mon, 25 Nov 2024 18:15:38 +0300 Subject: [PATCH 08/12] Adding docs --- .../Get-EntraBetaDeletedServicePrincipal.md | 261 ++++++++++++++++++ .../Get-EntraDeletedServicePrincipal.md | 261 ++++++++++++++++++ 2 files changed, 522 insertions(+) create mode 100644 module/docs/entra-powershell-beta/Microsoft.Graph.Entra.Beta/Get-EntraBetaDeletedServicePrincipal.md create mode 100644 module/docs/entra-powershell-v1.0/Microsoft.Graph.Entra/Get-EntraDeletedServicePrincipal.md diff --git a/module/docs/entra-powershell-beta/Microsoft.Graph.Entra.Beta/Get-EntraBetaDeletedServicePrincipal.md b/module/docs/entra-powershell-beta/Microsoft.Graph.Entra.Beta/Get-EntraBetaDeletedServicePrincipal.md new file mode 100644 index 0000000000..84cc3833f8 --- /dev/null +++ b/module/docs/entra-powershell-beta/Microsoft.Graph.Entra.Beta/Get-EntraBetaDeletedServicePrincipal.md @@ -0,0 +1,261 @@ +--- +title: Get-EntraBetaDeletedServicePrincipal +description: This article provides details on the Get-EntraBetaDeletedServicePrincipal command. + + +ms.topic: reference +ms.date: 11/14/2024 +ms.author: eunicewaweru +ms.reviewer: stevemutungi +manager: CelesteDG + +external help file: Microsoft.Graph.Entra.Beta-Help.xml +Module Name: Microsoft.Graph.Entra.Beta +online version: https://learn.microsoft.com/powershell/module/Microsoft.Graph.Entra.Beta/Get-EntraBetaDeletedServicePrincipal + +schema: 2.0.0 +--- + +# Get-EntraBetaDeletedServicePrincipal + +## Synopsis + +Retrieves the list of previously deleted service principals. + +## Syntax + +### GetQuery (Default) + +```powershell +Get-EntraBetaDeletedServicePrincipal + [-Filter ] + [-All] + [-Top ] + [-Property ] + [] +``` + +### GetByValue + +```powershell +Get-EntraBetaDeletedServicePrincipal + [-SearchString ] + [-All] + [-Property ] + [] +``` + +### GetById + +```powershell +Get-EntraBetaDeletedServicePrincipal + -ServicePrincipalId + [-All] + [-Property ] + [] +``` + +## Description + +The `Get-EntraBetaDeletedServicePrincipal` cmdlet Retrieves the list of previously deleted service principals. + +## Examples + +### Example 1: Get list of deleted service principals + +```powershell +Connect-Entra -Scopes 'Application.Read.All' +Get-EntraBetaDeletedServicePrincipal +``` + +```Output +DisplayName Id AppId SignInAudience ServicePrincipalType +----------- -- ----- -------------- -------------------- +Contoso Marketing bbbbbbbb-1111-2222-3333-cccccccccccc 00001111-aaaa-2222-bbbb-3333cccc4444 Application Application +ProjectWorkManagement aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb 22223333-cccc-4444-dddd-5555eeee6666 Application ManagedIdentity +Enterprise App1 dddddddd-3333-4444-5555-eeeeeeeeeeee 33334444-dddd-5555-eeee-6666ffff7777 Application ManagedIdentity +``` + +This cmdlet retrieves the list of deleted service principals. + +### Example 2: Get list of deleted service principals using All parameter + +```powershell +Connect-Entra -Scopes 'Application.Read.All' +Get-EntraBetaDeletedServicePrincipal -All +``` + +```Output +DisplayName Id AppId SignInAudience ServicePrincipalType +----------- -- ----- -------------- -------------------- +Contoso Marketing bbbbbbbb-1111-2222-3333-cccccccccccc 00001111-aaaa-2222-bbbb-3333cccc4444 Application Application +ProjectWorkManagement aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb 22223333-cccc-4444-dddd-5555eeee6666 Application ManagedIdentity +Enterprise App1 dddddddd-3333-4444-5555-eeeeeeeeeeee 33334444-dddd-5555-eeee-6666ffff7777 Application ManagedIdentity +``` + +This cmdlet retrieves the list of deleted service principals using All parameter. + +### Example 3: Get top two deleted service principals + +```powershell +Connect-Entra -Scopes 'Application.Read.All' +Get-EntraBetaDeletedServicePrincipal -Top 2 +``` + +```Output +DisplayName Id AppId SignInAudience ServicePrincipalType +----------- -- ----- -------------- -------------------- +Contoso Marketing bbbbbbbb-1111-2222-3333-cccccccccccc 00001111-aaaa-2222-bbbb-3333cccc4444 Application Application +ProjectWorkManagement aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb 22223333-cccc-4444-dddd-5555eeee6666 Application ManagedIdentity +``` + +This cmdlet retrieves top two deleted service principals. + +### Example 4: Get deleted service principals using SearchString parameter + +```powershell +Connect-Entra -Scopes 'Application.Read.All' +Get-EntraBetaDeletedServicePrincipal -SearchString 'Contoso Marketing' +``` + +```Output +DisplayName Id AppId SignInAudience ServicePrincipalType +----------- -- ----- -------------- -------------------- +Contoso Marketing bbbbbbbb-1111-2222-3333-cccccccccccc 00001111-aaaa-2222-bbbb-3333cccc4444 Application Application +``` + +This cmdlet retrieves deleted service principals using SearchString parameter. + +### Example 5: Get deleted service principals filter by display name + +```powershell +Connect-Entra -Scopes 'Application.Read.All' +Get-EntraBetaDeletedServicePrincipal -Filter "DisplayName eq 'Contoso Marketing'" +``` + +```Output +DisplayName Id AppId SignInAudience ServicePrincipalType +----------- -- ----- -------------- -------------------- +Contoso Marketing bbbbbbbb-1111-2222-3333-cccccccccccc 00001111-aaaa-2222-bbbb-3333cccc4444 Application Application +``` + +This cmdlet retrieves deleted service principals having specified display name. + +### Example 6: Get deleted service principal by ServicePrincipalId + +```powershell +Connect-Entra -Scopes 'Application.Read.All' +Get-EntraBetaDeletedServicePrincipal -ServicePrincipalId 'aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb' +``` + +```Output +DisplayName Id AppId SignInAudience ServicePrincipalType +----------- -- ----- -------------- -------------------- +Contoso Marketing bbbbbbbb-1111-2222-3333-cccccccccccc 00001111-aaaa-2222-bbbb-3333cccc4444 Application Application +``` + +This cmdlet retrieves the deleted service principal specified by ServicePrincipalId. + +- `-ServicePrincipalId` parameter specifies the deleted service principal Id. + +## Parameters + +### -All + +List all pages. + +```yaml +Type: System.Management.Automation.SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Filter + +Retrieve only those deleted service principals that satisfy the filter. + +```yaml +Type: System.String +Parameter Sets: GetQuery +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName, ByValue) +Accept wildcard characters: False +``` + +### -SearchString + +Retrieve only those service principals that satisfy the -SearchString value. + +```yaml +Type: System.String +Parameter Sets: GetVague +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName, ByValue) +Accept wildcard characters: False +``` + +### -Top + +The maximum number of service principals. + +```yaml +Type: System.Int32 +Parameter Sets: GetQuery +Aliases: Limit + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName, ByValue) +Accept wildcard characters: False +``` + +### -Property + +Specifies properties to be returned + +```yaml +Type: System.String[] +Parameter Sets: (All) +Aliases: Select + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters + +This cmdlet supports the common parameters: `-Debug`, `-ErrorAction`, `-ErrorVariable`, `-InformationAction`, `-InformationVariable`, `-OutVariable`, `-OutBuffer`, `-PipelineVariable`, `-Verbose`, `-WarningAction`, and `-WarningVariable`. For more information, see [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216). + +## Inputs + +### System.String + +System.Nullable\`1\[\[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\]\] System.Nullable\`1\[\[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\]\] + +## Outputs + +### System.Object + +## Notes + +## Related Links + +[Get-EntraApplication](Get-EntraApplication.md) diff --git a/module/docs/entra-powershell-v1.0/Microsoft.Graph.Entra/Get-EntraDeletedServicePrincipal.md b/module/docs/entra-powershell-v1.0/Microsoft.Graph.Entra/Get-EntraDeletedServicePrincipal.md new file mode 100644 index 0000000000..331edde4b3 --- /dev/null +++ b/module/docs/entra-powershell-v1.0/Microsoft.Graph.Entra/Get-EntraDeletedServicePrincipal.md @@ -0,0 +1,261 @@ +--- +title: Get-EntraDeletedServicePrincipal +description: This article provides details on the Get-EntraDeletedServicePrincipal command. + + +ms.topic: reference +ms.date: 11/14/2024 +ms.author: eunicewaweru +ms.reviewer: stevemutungi +manager: CelesteDG + +external help file: Microsoft.Graph.Entra-Help.xml +Module Name: Microsoft.Graph.Entra +online version: https://learn.microsoft.com/powershell/module/Microsoft.Graph.Entra/Get-EntraDeletedServicePrincipal + +schema: 2.0.0 +--- + +# Get-EntraDeletedServicePrincipal + +## Synopsis + +Retrieves the list of previously deleted service principals. + +## Syntax + +### GetQuery (Default) + +```powershell +Get-EntraDeletedServicePrincipal + [-Filter ] + [-All] + [-Top ] + [-Property ] + [] +``` + +### GetByValue + +```powershell +Get-EntraDeletedServicePrincipal + [-SearchString ] + [-All] + [-Property ] + [] +``` + +### GetById + +```powershell +Get-EntraDeletedServicePrincipal + -ServicePrincipalId + [-All] + [-Property ] + [] +``` + +## Description + +The `Get-EntraDeletedServicePrincipal` cmdlet Retrieves the list of previously deleted service principals. + +## Examples + +### Example 1: Get list of deleted service principals + +```powershell +Connect-Entra -Scopes 'Application.Read.All' +Get-EntraDeletedServicePrincipal +``` + +```Output +DisplayName Id AppId SignInAudience ServicePrincipalType +----------- -- ----- -------------- -------------------- +Contoso Marketing bbbbbbbb-1111-2222-3333-cccccccccccc 00001111-aaaa-2222-bbbb-3333cccc4444 Application Application +ProjectWorkManagement aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb 22223333-cccc-4444-dddd-5555eeee6666 Application ManagedIdentity +Enterprise App1 dddddddd-3333-4444-5555-eeeeeeeeeeee 33334444-dddd-5555-eeee-6666ffff7777 Application ManagedIdentity +``` + +This cmdlet retrieves the list of deleted service principals. + +### Example 2: Get list of deleted service principals using All parameter + +```powershell +Connect-Entra -Scopes 'Application.Read.All' +Get-EntraDeletedServicePrincipal -All +``` + +```Output +DisplayName Id AppId SignInAudience ServicePrincipalType +----------- -- ----- -------------- -------------------- +Contoso Marketing bbbbbbbb-1111-2222-3333-cccccccccccc 00001111-aaaa-2222-bbbb-3333cccc4444 Application Application +ProjectWorkManagement aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb 22223333-cccc-4444-dddd-5555eeee6666 Application ManagedIdentity +Enterprise App1 dddddddd-3333-4444-5555-eeeeeeeeeeee 33334444-dddd-5555-eeee-6666ffff7777 Application ManagedIdentity +``` + +This cmdlet retrieves the list of deleted service principals using All parameter. + +### Example 3: Get top two deleted service principals + +```powershell +Connect-Entra -Scopes 'Application.Read.All' +Get-EntraDeletedServicePrincipal -Top 2 +``` + +```Output +DisplayName Id AppId SignInAudience ServicePrincipalType +----------- -- ----- -------------- -------------------- +Contoso Marketing bbbbbbbb-1111-2222-3333-cccccccccccc 00001111-aaaa-2222-bbbb-3333cccc4444 Application Application +ProjectWorkManagement aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb 22223333-cccc-4444-dddd-5555eeee6666 Application ManagedIdentity +``` + +This cmdlet retrieves top two deleted service principals. + +### Example 4: Get deleted service principals using SearchString parameter + +```powershell +Connect-Entra -Scopes 'Application.Read.All' +Get-EntraDeletedServicePrincipal -SearchString 'Contoso Marketing' +``` + +```Output +DisplayName Id AppId SignInAudience ServicePrincipalType +----------- -- ----- -------------- -------------------- +Contoso Marketing bbbbbbbb-1111-2222-3333-cccccccccccc 00001111-aaaa-2222-bbbb-3333cccc4444 Application Application +``` + +This cmdlet retrieves deleted service principals using SearchString parameter. + +### Example 5: Get deleted service principals filter by display name + +```powershell +Connect-Entra -Scopes 'Application.Read.All' +Get-EntraDeletedServicePrincipal -Filter "DisplayName eq 'Contoso Marketing'" +``` + +```Output +DisplayName Id AppId SignInAudience ServicePrincipalType +----------- -- ----- -------------- -------------------- +Contoso Marketing bbbbbbbb-1111-2222-3333-cccccccccccc 00001111-aaaa-2222-bbbb-3333cccc4444 Application Application +``` + +This cmdlet retrieves deleted service principals having specified display name. + +### Example 6: Get deleted service principal by ServicePrincipalId + +```powershell +Connect-Entra -Scopes 'Application.Read.All' +Get-EntraDeletedServicePrincipal -ServicePrincipalId 'aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb' +``` + +```Output +DisplayName Id AppId SignInAudience ServicePrincipalType +----------- -- ----- -------------- -------------------- +Contoso Marketing bbbbbbbb-1111-2222-3333-cccccccccccc 00001111-aaaa-2222-bbbb-3333cccc4444 Application Application +``` + +This cmdlet retrieves the deleted service principal specified by ServicePrincipalId. + +- `-ServicePrincipalId` parameter specifies the deleted service principal Id. + +## Parameters + +### -All + +List all pages. + +```yaml +Type: System.Management.Automation.SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Filter + +Retrieve only those deleted service principals that satisfy the filter. + +```yaml +Type: System.String +Parameter Sets: GetQuery +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName, ByValue) +Accept wildcard characters: False +``` + +### -SearchString + +Retrieve only those service principals that satisfy the -SearchString value. + +```yaml +Type: System.String +Parameter Sets: GetVague +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName, ByValue) +Accept wildcard characters: False +``` + +### -Top + +The maximum number of service principals. + +```yaml +Type: System.Int32 +Parameter Sets: GetQuery +Aliases: Limit + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName, ByValue) +Accept wildcard characters: False +``` + +### -Property + +Specifies properties to be returned + +```yaml +Type: System.String[] +Parameter Sets: (All) +Aliases: Select + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters + +This cmdlet supports the common parameters: `-Debug`, `-ErrorAction`, `-ErrorVariable`, `-InformationAction`, `-InformationVariable`, `-OutVariable`, `-OutBuffer`, `-PipelineVariable`, `-Verbose`, `-WarningAction`, and `-WarningVariable`. For more information, see [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216). + +## Inputs + +### System.String + +System.Nullable\`1\[\[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\]\] System.Nullable\`1\[\[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\]\] + +## Outputs + +### System.Object + +## Notes + +## Related Links + +[Get-EntraApplication](Get-EntraApplication.md) From 74dd30b8bc4a05dd4db13c073894b76dcb251099 Mon Sep 17 00:00:00 2001 From: Steve Mutungi <132555836+SteveMutungi254@users.noreply.github.com> Date: Mon, 25 Nov 2024 18:26:59 +0300 Subject: [PATCH 09/12] Fix - build error --- .../Get-EntraBetaDeletedServicePrincipal.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/docs/entra-powershell-beta/Microsoft.Graph.Entra.Beta/Get-EntraBetaDeletedServicePrincipal.md b/module/docs/entra-powershell-beta/Microsoft.Graph.Entra.Beta/Get-EntraBetaDeletedServicePrincipal.md index 84cc3833f8..4c9a13da7f 100644 --- a/module/docs/entra-powershell-beta/Microsoft.Graph.Entra.Beta/Get-EntraBetaDeletedServicePrincipal.md +++ b/module/docs/entra-powershell-beta/Microsoft.Graph.Entra.Beta/Get-EntraBetaDeletedServicePrincipal.md @@ -258,4 +258,4 @@ System.Nullable\`1\[\[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral ## Related Links -[Get-EntraApplication](Get-EntraApplication.md) +[Get-EntraBetaApplication](Get-EntraBetaApplication.md) From 377a8b734e4c1bef0de2a7d3a89fa2e4954670dc Mon Sep 17 00:00:00 2001 From: Steve Mutungi <132555836+SteveMutungi254@users.noreply.github.com> Date: Tue, 26 Nov 2024 08:31:15 +0000 Subject: [PATCH 10/12] Adding service principal Id property documentation --- .../Get-EntraBetaDeletedServicePrincipal.md | 16 ++++++++++++++++ .../Get-EntraDeletedServicePrincipal.md | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/module/docs/entra-powershell-beta/Microsoft.Graph.Entra.Beta/Get-EntraBetaDeletedServicePrincipal.md b/module/docs/entra-powershell-beta/Microsoft.Graph.Entra.Beta/Get-EntraBetaDeletedServicePrincipal.md index 4c9a13da7f..d7ff9cd4d1 100644 --- a/module/docs/entra-powershell-beta/Microsoft.Graph.Entra.Beta/Get-EntraBetaDeletedServicePrincipal.md +++ b/module/docs/entra-powershell-beta/Microsoft.Graph.Entra.Beta/Get-EntraBetaDeletedServicePrincipal.md @@ -240,6 +240,22 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ServicePrincipalId + +The unique ID of the deleted service principal to be retrieved. + +```yaml +Type: System.String +Parameter Sets: GetById +Aliases: Id + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName, ByValue) +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: `-Debug`, `-ErrorAction`, `-ErrorVariable`, `-InformationAction`, `-InformationVariable`, `-OutVariable`, `-OutBuffer`, `-PipelineVariable`, `-Verbose`, `-WarningAction`, and `-WarningVariable`. For more information, see [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/module/docs/entra-powershell-v1.0/Microsoft.Graph.Entra/Get-EntraDeletedServicePrincipal.md b/module/docs/entra-powershell-v1.0/Microsoft.Graph.Entra/Get-EntraDeletedServicePrincipal.md index 331edde4b3..c81a9e8fb8 100644 --- a/module/docs/entra-powershell-v1.0/Microsoft.Graph.Entra/Get-EntraDeletedServicePrincipal.md +++ b/module/docs/entra-powershell-v1.0/Microsoft.Graph.Entra/Get-EntraDeletedServicePrincipal.md @@ -240,6 +240,22 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ServicePrincipalId + +The unique ID of the deleted service principal to be retrieved. + +```yaml +Type: System.String +Parameter Sets: GetById +Aliases: Id + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName, ByValue) +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: `-Debug`, `-ErrorAction`, `-ErrorVariable`, `-InformationAction`, `-InformationVariable`, `-OutVariable`, `-OutBuffer`, `-PipelineVariable`, `-Verbose`, `-WarningAction`, and `-WarningVariable`. For more information, see [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216). From 8c7a444e9f0651e2a17ff002add6c6c8a5796f8b Mon Sep 17 00:00:00 2001 From: Steve Mutungi <132555836+SteveMutungi254@users.noreply.github.com> Date: Mon, 9 Dec 2024 05:02:21 +0000 Subject: [PATCH 11/12] Adding pagesize --- .../Get-EntraDeletedServicePrincipal.ps1 | 9 ++++++--- .../Get-EntraBetaDeletedServicePrincipal.ps1 | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/module/Entra/AdditionalFunctions/Get-EntraDeletedServicePrincipal.ps1 b/module/Entra/AdditionalFunctions/Get-EntraDeletedServicePrincipal.ps1 index 8c7ee7186c..cf0a9d3408 100644 --- a/module/Entra/AdditionalFunctions/Get-EntraDeletedServicePrincipal.ps1 +++ b/module/Entra/AdditionalFunctions/Get-EntraDeletedServicePrincipal.ps1 @@ -101,9 +101,12 @@ function Get-EntraDeletedServicePrincipal { try { # Make the API call - $response = Get-MgDirectoryDeletedItemAsServicePrincipal @params -Headers $customHeaders - - return $response + if ($PSBoundParameters.ContainsKey("All") -and $All) { + $response = Get-MgDirectoryDeletedItemAsServicePrincipal @params -PageSize 999 -Headers $customHeaders + } + else { + $response = Get-MgDirectoryDeletedItemAsServicePrincipal @params -Headers $customHeaders + } } catch { # Handle any errors that occur during the API call diff --git a/module/EntraBeta/AdditionalFunctions/Get-EntraBetaDeletedServicePrincipal.ps1 b/module/EntraBeta/AdditionalFunctions/Get-EntraBetaDeletedServicePrincipal.ps1 index 659f6b78f2..6850c0a3b3 100644 --- a/module/EntraBeta/AdditionalFunctions/Get-EntraBetaDeletedServicePrincipal.ps1 +++ b/module/EntraBeta/AdditionalFunctions/Get-EntraBetaDeletedServicePrincipal.ps1 @@ -101,9 +101,12 @@ function Get-EntraBetaDeletedServicePrincipal { try { # Make the API call - $response = Get-MgBetaDirectoryDeletedItemAsServicePrincipal @params -Headers $customHeaders - - return $response + if ($PSBoundParameters.ContainsKey("All") -and $All) { + $response = Get-MgBetaDirectoryDeletedItemAsServicePrincipal @params -PageSize 999 -Headers $customHeaders + } + else { + $response = Get-MgBetaDirectoryDeletedItemAsServicePrincipal @params -Headers $customHeaders + } } catch { # Handle any errors that occur during the API call From 89453ffee1c8d6160e36ca4c326de12281075dc4 Mon Sep 17 00:00:00 2001 From: Steve Mutungi <132555836+SteveMutungi254@users.noreply.github.com> Date: Mon, 9 Dec 2024 05:43:55 +0000 Subject: [PATCH 12/12] Add response statement --- .../AdditionalFunctions/Get-EntraDeletedServicePrincipal.ps1 | 2 ++ .../Get-EntraBetaDeletedServicePrincipal.ps1 | 2 ++ 2 files changed, 4 insertions(+) diff --git a/module/Entra/AdditionalFunctions/Get-EntraDeletedServicePrincipal.ps1 b/module/Entra/AdditionalFunctions/Get-EntraDeletedServicePrincipal.ps1 index cf0a9d3408..86b30b6a57 100644 --- a/module/Entra/AdditionalFunctions/Get-EntraDeletedServicePrincipal.ps1 +++ b/module/Entra/AdditionalFunctions/Get-EntraDeletedServicePrincipal.ps1 @@ -107,6 +107,8 @@ function Get-EntraDeletedServicePrincipal { else { $response = Get-MgDirectoryDeletedItemAsServicePrincipal @params -Headers $customHeaders } + + return $response } catch { # Handle any errors that occur during the API call diff --git a/module/EntraBeta/AdditionalFunctions/Get-EntraBetaDeletedServicePrincipal.ps1 b/module/EntraBeta/AdditionalFunctions/Get-EntraBetaDeletedServicePrincipal.ps1 index 6850c0a3b3..bab830774c 100644 --- a/module/EntraBeta/AdditionalFunctions/Get-EntraBetaDeletedServicePrincipal.ps1 +++ b/module/EntraBeta/AdditionalFunctions/Get-EntraBetaDeletedServicePrincipal.ps1 @@ -107,6 +107,8 @@ function Get-EntraBetaDeletedServicePrincipal { else { $response = Get-MgBetaDirectoryDeletedItemAsServicePrincipal @params -Headers $customHeaders } + + return $response } catch { # Handle any errors that occur during the API call