Skip to content

Commit

Permalink
Ignore error on Get if policy does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien Tschanz committed Jan 23, 2025
1 parent 69f94be commit 5b0a8b0
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@
* Fixes an issue where not all details were exported.
* IntuneAccountProtectionPolicy
* Fixes an issue where not all details were exported.
* IntuneAppConfigurationPolicy
* Fixes an issue with fetching a policy that does not exist.
FIXES [#5666](https://github.com/microsoft/Microsoft365DSC/issues/5666)
* IntuneApplicationControlPolicyWindows10
* Fixes an issue with fetching a policy that does not exist.
* IntuneAppProtectionPolicyAndroid
* Fixes an issue with fetching a policy that does not exist.
* IntuneDeviceEnrollmentPlatformRestriction
* Fixes an issue with fetching a policy that does not exist.
* M365DSCReverse
* Only fetch tenant name if not in correct format.

# 1.25.122.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function Get-TargetResource
if (-not [string]::IsNullOrEmpty($Id))
{
$configPolicy = Get-MgBetaDeviceAppManagementTargetedManagedAppConfiguration -TargetedManagedAppConfigurationId $Id `
-ErrorAction Stop
-ErrorAction SilentlyContinue
}

if ($null -eq $configPolicy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ function Get-TargetResource
{
Write-Verbose -Message "Searching for Policy using Id {$Id}"
$policyInfo = Get-MgBetaDeviceAppManagementAndroidManagedAppProtection -Filter "Id eq '$Id'" -ExpandProperty Apps, assignments `
-ErrorAction Stop
-ErrorAction SilentlyContinue
}

if ($null -eq $policyInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function Get-TargetResource
#Retrieve policy general settings
if (-not [System.String]::IsNullOrEmpty($Id))
{
$policy = Get-MgBetaDeviceManagementIntent -DeviceManagementIntentId $Id -ErrorAction Stop
$policy = Get-MgBetaDeviceManagementIntent -DeviceManagementIntentId $Id -ErrorAction SilentlyContinue
}

if ($null -eq $policy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function Get-TargetResource
$config = $null
if (-not [string]::IsNullOrEmpty($Identity))
{
$config = Get-MgBetaDeviceManagementDeviceEnrollmentConfiguration -DeviceEnrollmentConfigurationId $Identity -ErrorAction Stop
$config = Get-MgBetaDeviceManagementDeviceEnrollmentConfiguration -DeviceEnrollmentConfigurationId $Identity -ErrorAction SilentlyContinue
}

if ($null -eq $config)
Expand Down
17 changes: 12 additions & 5 deletions Modules/Microsoft365DSC/Modules/M365DSCReverse.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,18 @@ function Start-M365DSCConfigurationExtract
[PSCredential]$AppSecretAsPSCredential = New-Object System.Management.Automation.PSCredential ('ApplicationSecret', $secStringPassword)
}

$organization = Get-M365DSCTenantDomain -ApplicationId $ApplicationId `
-TenantId $TenantId `
-CertificateThumbprint $CertificateThumbprint `
-ApplicationSecret $AppSecretAsPSCredential `
-CertificatePath $CertificatePath
if ($TenantId -like "*.onmicrosoft.com")
{
$organization = $TenantId
}
else
{
$organization = Get-M365DSCTenantDomain -ApplicationId $ApplicationId `
-TenantId $TenantId `
-CertificateThumbprint $CertificateThumbprint `
-ApplicationSecret $AppSecretAsPSCredential `
-CertificatePath $CertificatePath
}
}
elseif ($AuthMethods -Contains 'Credentials' -or `
$AuthMethods -Contains 'CredentialsWithApplicationId')
Expand Down

0 comments on commit 5b0a8b0

Please sign in to comment.