26 lines
1007 B
PowerShell
26 lines
1007 B
PowerShell
# 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
|