chore: add compliance policy import to main script

This commit is contained in:
2025-03-17 15:01:33 +10:00
parent 6ebfed511f
commit 7d36e0a147
2 changed files with 23 additions and 30 deletions

View File

@ -65,8 +65,8 @@ Write-Host "✅ Successfully created group $group"
$policies = Get-ChildItem ./policies/settingscatalog
ForEach ($policie in $policies) {
$PolicyName = $policie.name
ForEach ($policy in $policies) {
$PolicyName = $policy.name
$JsonData = Get-Content -Path ./policies/settingscatalog/$PolicieName -Raw
$JsonDataUpdated = $JsonData -replace '\$tenantId', $tenantId
@ -81,6 +81,24 @@ ForEach ($policie in $policies) {
}
}
$policies = Get-ChildItem ./policies/compliance
ForEach ($policy in $policies) {
$PolicyName = $policy.name
$JsonData = Get-Content -Path ./policies/compliance/$PolicyName -Raw
$JsonDataUpdated = $JsonData -replace '\$tenantId', $tenantId
$PolicyObject = $JsonDataUpdated | ConvertFrom-Json
try {
$uri = "https://graph.microsoft.com/beta/deviceManagement/deviceCompliancePolicies" # Using the beta version
$null = Invoke-MgGraphRequest -Method POST -Uri $uri -Body ($PolicyObject | ConvertTo-Json -Depth 10)
Write-Host "$PolicyName - successfully imported!"
} catch {
Write-Error "❌ An error occurred while importing the policy: $_"
}
}
# Create Windows Update Ring Policies
# Create a baseline policy using web interface
@ -225,7 +243,7 @@ $ring = $body.displayName
$groupBodyJson = $Body | ConvertTo-Json -Depth 10
# Send the POST request to create the Driver Update Profile
$response = Invoke-MgGraphRequest -Method POST -Uri $uri -Body $groupBodyJson -ContentType "application/json"
$null = Invoke-MgGraphRequest -Method POST -Uri $uri -Body $groupBodyJson -ContentType "application/json"
Write-Host "✅ Successfully created group $ring"
@ -245,7 +263,7 @@ $ring = $body.displayName
$groupBodyJson = $Body | ConvertTo-Json -Depth 10
# Send the POST request to create the Driver Update Profile
$response = Invoke-MgGraphRequest -Method POST -Uri $uri -Body $groupBodyJson -ContentType "application/json"
$null = Invoke-MgGraphRequest -Method POST -Uri $uri -Body $groupBodyJson -ContentType "application/json"
Write-Host "✅ Successfully created group $ring"
@ -264,7 +282,7 @@ $ring = $body.displayName
$groupBodyJson = $Body | ConvertTo-Json -Depth 10
# Send the POST request to create the Driver Update Profile
$response = Invoke-MgGraphRequest -Method POST -Uri $uri -Body $groupBodyJson -ContentType "application/json"
$null = Invoke-MgGraphRequest -Method POST -Uri $uri -Body $groupBodyJson -ContentType "application/json"
Write-Host "✅ Successfully created group $ring"
$null = Disconnect-Graph -ErrorAction SilentlyContinue