chore: add compliance policy import to main script
This commit is contained in:
@ -1,25 +0,0 @@
|
|||||||
# Connect to Microsoft Graph
|
|
||||||
Connect-MgGraph -Scopes "DeviceManagementConfiguration.ReadWrite.All", "Organization.Read.All", "Group.ReadWrite.All", "Directory.ReadWrite.All" -NoWelcome
|
|
||||||
|
|
||||||
$policies = Get-ChildItem ./policies/compliance
|
|
||||||
|
|
||||||
ForEach ($policie in $policies) {
|
|
||||||
$PolicieName = $policie.name
|
|
||||||
|
|
||||||
$JsonData = Get-Content -Path ./policies/compliance/$PolicieName -Raw
|
|
||||||
$JsonDataUpdated = $JsonData -replace '\$tenantId', $tenantId
|
|
||||||
$PolicyObject = $JsonDataUpdated | ConvertFrom-Json
|
|
||||||
|
|
||||||
try {
|
|
||||||
$uri = "https://graph.microsoft.com/beta/deviceManagement/deviceCompliancePolicies" # Using the beta version
|
|
||||||
$response = Invoke-MgGraphRequest -Method POST -Uri $uri -Body ($PolicyObject | ConvertTo-Json -Depth 10)
|
|
||||||
Write-Host "✅ $PolicieName - successfully imported!"
|
|
||||||
#$response
|
|
||||||
} catch {
|
|
||||||
Write-Error "❌ An error occurred while importing the policy: $_"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Disconnect from Graph
|
|
||||||
$null = Disconnect-Graph -ErrorAction SilentlyContinue
|
|
@ -65,8 +65,8 @@ Write-Host "✅ Successfully created group $group"
|
|||||||
|
|
||||||
$policies = Get-ChildItem ./policies/settingscatalog
|
$policies = Get-ChildItem ./policies/settingscatalog
|
||||||
|
|
||||||
ForEach ($policie in $policies) {
|
ForEach ($policy in $policies) {
|
||||||
$PolicyName = $policie.name
|
$PolicyName = $policy.name
|
||||||
|
|
||||||
$JsonData = Get-Content -Path ./policies/settingscatalog/$PolicieName -Raw
|
$JsonData = Get-Content -Path ./policies/settingscatalog/$PolicieName -Raw
|
||||||
$JsonDataUpdated = $JsonData -replace '\$tenantId', $tenantId
|
$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 Windows Update Ring Policies
|
||||||
# Create a baseline policy using web interface
|
# Create a baseline policy using web interface
|
||||||
@ -225,7 +243,7 @@ $ring = $body.displayName
|
|||||||
$groupBodyJson = $Body | ConvertTo-Json -Depth 10
|
$groupBodyJson = $Body | ConvertTo-Json -Depth 10
|
||||||
|
|
||||||
# Send the POST request to create the Driver Update Profile
|
# 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"
|
Write-Host "✅ Successfully created group $ring"
|
||||||
|
|
||||||
|
|
||||||
@ -245,7 +263,7 @@ $ring = $body.displayName
|
|||||||
$groupBodyJson = $Body | ConvertTo-Json -Depth 10
|
$groupBodyJson = $Body | ConvertTo-Json -Depth 10
|
||||||
|
|
||||||
# Send the POST request to create the Driver Update Profile
|
# 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"
|
Write-Host "✅ Successfully created group $ring"
|
||||||
|
|
||||||
|
|
||||||
@ -264,7 +282,7 @@ $ring = $body.displayName
|
|||||||
$groupBodyJson = $Body | ConvertTo-Json -Depth 10
|
$groupBodyJson = $Body | ConvertTo-Json -Depth 10
|
||||||
|
|
||||||
# Send the POST request to create the Driver Update Profile
|
# 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"
|
Write-Host "✅ Successfully created group $ring"
|
||||||
|
|
||||||
$null = Disconnect-Graph -ErrorAction SilentlyContinue
|
$null = Disconnect-Graph -ErrorAction SilentlyContinue
|
Reference in New Issue
Block a user