IntuneManagement 4.0.0-beta1

This commit is contained in:
Mikael Karlsson
2026-09-23 19:13:09 +10:00
commit 7869619510
892 changed files with 577109 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
function Remove-GraphPolicy {
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')]
[OutputType([IntunePolicyBase[]])]
param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[IntunePolicyBase[]]
$InputObject,
# Specifies destination environment. Default is current logged on environment.
[int]
$TokenId = 0
)
Begin {
Write-LogDebug "Start deleting policies"
$deleted = @()
$bulkDelete = $null
if (Test-GraphBatchEnabled) {
$bulkDelete = @{}
}
}
Process {
foreach ($policyObject in $InputObject) {
if ($PSCmdlet.ShouldProcess($policyObject.Name, 'DELETE')) {
if ($policyObject.Delete($bulkDelete) -and -not $bulkDelete) {
$deleted += $policyObject
}
}
}
}
End {
if($bulkDelete.Count -gt 0) {
$batchObjects = [System.Collections.Generic.List[PSCustomObject]]::new()
$bulkDelete.Keys | ForEach-Object { $batchObjects.Add($_) }
$batchResults = Invoke-GraphBatchRequest -BatchObject $batchObjects -TokenId $TokenId -BatchType "Delete"
$batchResults | ForEach-Object {
$result = $_
$policy = $bulkDelete.Values | Where-Object Id -eq $_.Id
if ($result.Status -ge 200 -and $result.Status -lt 300) {
$deleted += $policy
Write-Log "Policy $($policy.Name) ($($policy.Id)) deleted successfully"
}
else {
Write-LogError "Failed to delete policy $($policy.Name) ($($policy.Id)). Status code: $($result.Status) $($result.ErrorMessage)"
}
}
}
Write-LogDebug "Delete policy finished"
return $deleted
}
}