@@ -35,8 +35,8 @@ function Get-CIPPIntunePolicy {
3535 $iOSPolicies = ($BulkResults | Where-Object { $_.id -eq ' iOSPolicies' }).body.value
3636
3737 if ($DisplayName ) {
38- $androidPolicy = $androidPolicies | Where-Object - Property displayName -EQ $DisplayName
39- $iOSPolicy = $iOSPolicies | Where-Object - Property displayName -EQ $DisplayName
38+ $androidPolicy = $androidPolicies | Where-Object - Property displayName -EQ $DisplayName | Sort-Object - Property lastModifiedDateTime - Descending | Select-Object - First 1
39+ $iOSPolicy = $iOSPolicies | Where-Object - Property displayName -EQ $DisplayName | Sort-Object - Property lastModifiedDateTime - Descending | Select-Object - First 1
4040
4141 # Return the matching policy (Android or iOS) - using full data from bulk request
4242 if ($androidPolicy ) {
@@ -92,7 +92,7 @@ function Get-CIPPIntunePolicy {
9292
9393 if ($DisplayName ) {
9494 $policies = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL " - tenantid $tenantFilter
95- $policy = $policies | Where-Object - Property displayName -EQ $DisplayName
95+ $policy = $policies | Where-Object - Property displayName -EQ $DisplayName | Sort-Object - Property lastModifiedDateTime - Descending | Select-Object - First 1
9696 if ($policy ) {
9797 $policyDetails = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL ('$ ( $policy.id ) ')?`$ expand=scheduledActionsForRule(`$ expand=scheduledActionConfigurations)" - tenantid $tenantFilter
9898 $policyJson = ConvertTo-Json - InputObject $policyDetails - Depth 100 - Compress
@@ -122,7 +122,7 @@ function Get-CIPPIntunePolicy {
122122
123123 if ($DisplayName ) {
124124 $policies = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL " - tenantid $tenantFilter
125- $policy = $policies | Where-Object - Property displayName -EQ $DisplayName
125+ $policy = $policies | Where-Object - Property displayName -EQ $DisplayName | Sort-Object - Property lastModifiedDateTime - Descending | Select-Object - First 1
126126 if ($policy ) {
127127 $definitionValues = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL ('$ ( $policy.id ) ')/definitionValues" - tenantid $tenantFilter
128128 $policy | Add-Member - MemberType NoteProperty - Name ' definitionValues' - Value $definitionValues - Force
@@ -237,7 +237,7 @@ function Get-CIPPIntunePolicy {
237237
238238 if ($DisplayName ) {
239239 $policies = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL " - tenantid $tenantFilter
240- $policy = $policies | Where-Object - Property displayName -EQ $DisplayName
240+ $policy = $policies | Where-Object - Property displayName -EQ $DisplayName | Sort-Object - Property lastModifiedDateTime - Descending | Select-Object - First 1
241241 if ($policy ) {
242242 $policyDetails = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL ('$ ( $policy.id ) ')" - tenantid $tenantFilter
243243 $policyDetails = $policyDetails | Select-Object * - ExcludeProperty id, lastModifiedDateTime, ' @odata.context' , ' ScopeTagIds' , ' supportsScopeTags' , ' createdDateTime'
@@ -270,7 +270,7 @@ function Get-CIPPIntunePolicy {
270270
271271 if ($DisplayName ) {
272272 $policies = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL " - tenantid $tenantFilter
273- $policy = $policies | Where-Object - Property Name -EQ $DisplayName
273+ $policy = $policies | Where-Object - Property Name -EQ $DisplayName | Sort-Object - Property lastModifiedDateTime - Descending | Select-Object - First 1
274274 if ($policy ) {
275275 $policyDetails = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL ('$ ( $policy.id ) ')?`$ expand=settings" - tenantid $tenantFilter
276276 $policyDetails = $policyDetails | Select-Object name, description, settings, platforms, technologies, templateReference
@@ -303,7 +303,7 @@ function Get-CIPPIntunePolicy {
303303
304304 if ($DisplayName ) {
305305 $policies = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL " - tenantid $tenantFilter
306- $policy = $policies | Where-Object - Property displayName -EQ $DisplayName
306+ $policy = $policies | Where-Object - Property displayName -EQ $DisplayName | Sort-Object - Property lastModifiedDateTime - Descending | Select-Object - First 1
307307 if ($policy ) {
308308 $policyDetails = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL ('$ ( $policy.id ) ')" - tenantid $tenantFilter
309309 $policyDetails = $policyDetails | Select-Object * - ExcludeProperty id, lastModifiedDateTime, ' @odata.context' , ' ScopeTagIds' , ' supportsScopeTags' , ' createdDateTime'
@@ -336,7 +336,7 @@ function Get-CIPPIntunePolicy {
336336
337337 if ($DisplayName ) {
338338 $policies = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL " - tenantid $tenantFilter
339- $policy = $policies | Where-Object - Property displayName -EQ $DisplayName
339+ $policy = $policies | Where-Object - Property displayName -EQ $DisplayName | Sort-Object - Property lastModifiedDateTime - Descending | Select-Object - First 1
340340 if ($policy ) {
341341 $policyDetails = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL ('$ ( $policy.id ) ')" - tenantid $tenantFilter
342342 $policyDetails = $policyDetails | Select-Object * - ExcludeProperty id, lastModifiedDateTime, ' @odata.context' , ' ScopeTagIds' , ' supportsScopeTags' , ' createdDateTime'
@@ -369,7 +369,7 @@ function Get-CIPPIntunePolicy {
369369
370370 if ($DisplayName ) {
371371 $policies = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL " - tenantid $tenantFilter
372- $policy = $policies | Where-Object - Property displayName -EQ $DisplayName
372+ $policy = $policies | Where-Object - Property displayName -EQ $DisplayName | Sort-Object - Property lastModifiedDateTime - Descending | Select-Object - First 1
373373 if ($policy ) {
374374 $policyDetails = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL ('$ ( $policy.id ) ')" - tenantid $tenantFilter
375375 $policyDetails = $policyDetails | Select-Object * - ExcludeProperty id, lastModifiedDateTime, ' @odata.context' , ' ScopeTagIds' , ' supportsScopeTags' , ' createdDateTime'
@@ -402,7 +402,7 @@ function Get-CIPPIntunePolicy {
402402
403403 if ($DisplayName ) {
404404 $policies = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL " - tenantid $tenantFilter
405- $policy = $policies | Where-Object - Property displayName -EQ $DisplayName
405+ $policy = $policies | Where-Object - Property displayName -EQ $DisplayName | Sort-Object - Property lastModifiedDateTime - Descending | Select-Object - First 1
406406 if ($policy ) {
407407 $policyDetails = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL ('$ ( $policy.id ) ')" - tenantid $tenantFilter
408408 $policyDetails = $policyDetails | Select-Object * - ExcludeProperty id, lastModifiedDateTime, ' @odata.context' , ' ScopeTagIds' , ' supportsScopeTags' , ' createdDateTime'
0 commit comments