Skip to content

Commit a04a2f1

Browse files
authored
Add initial scripts for uploading Defender configuration profiles to Intune (#204)
1 parent 18987b1 commit a04a2f1

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
############################################################################################
2+
##
3+
## This script uploads custom macOS configuration profiles to Microsoft Intune using the Microsoft Graph API.
4+
##
5+
############################################################################################
6+
7+
## Copyright (c) 2025 Microsoft Corp. All rights reserved.
8+
## Scripts are not supported under any Microsoft standard support program or service. The scripts are provided AS IS without warranty of any kind.
9+
## Microsoft disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a
10+
## particular purpose. The entire risk arising out of the use or performance of the scripts and documentation remains with you. In no event shall
11+
## Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever
12+
## (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary
13+
## loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility
14+
## of such damages.
15+
## Feedback: [email protected]
16+
#
17+
18+
#################################################
19+
# Configuration Variables
20+
#################################################
21+
22+
# Modify the $policyPrefix variable to change the prefix for the configuration names.
23+
# This prefix will be prepended to each configuration profile name in Intune
24+
$policyPrefix = "MDE (imported) - "
25+
26+
# Array of Microsoft Defender for Endpoint (MDE) mobile configuration files to upload
27+
# These files contain various security and permission settings for macOS devices
28+
$files = @(
29+
"accessibility.mobileconfig", # Accessibility permissions for MDE
30+
"background_services.mobileconfig", # Background service permissions
31+
"bluetooth.mobileconfig", # Bluetooth access permissions
32+
"fulldisk.mobileconfig", # Full disk access permissions
33+
"kext.mobileconfig", # Kernel extension permissions
34+
"netfilter.mobileconfig", # Network filter permissions
35+
"notif.mobileconfig", # Notification permissions
36+
"sysext.mobileconfig", # System extension permissions
37+
"sysext_restricted.mobileconfig" # Restricted system extension permissions
38+
)
39+
40+
#################################################
41+
# Prerequisites and Authentication
42+
#################################################
43+
44+
# Ensure you have the Microsoft Graph PowerShell SDK installed
45+
# Run this command if you haven't installed it yet:
46+
# Install-Module Microsoft.Graph -Scope CurrentUser
47+
48+
# Connect to Microsoft Graph with the required permissions for device configuration management
49+
# This will prompt for authentication if not already signed in
50+
Connect-MgGraph -NoWelcome -Scopes "DeviceManagementConfiguration.ReadWrite.All"
51+
52+
#################################################
53+
# Main Processing Loop
54+
#################################################
55+
56+
# Process each mobile configuration file
57+
foreach ($file in $files) {
58+
$FileContent = (Invoke-WebRequest -Uri "https://raw.githubusercontent.com/microsoft/mdatp-xplat/refs/heads/master/macos/mobileconfig/profiles/$file" -Method GET).Content
59+
$payload = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($FileContent))
60+
$FileName = $file -replace ".mobileconfig",""
61+
$json = '{
62+
"id": "00000000-0000-0000-0000-000000000000",
63+
"displayName": "' + $policyPrefix + $FileName + ' Configuration",
64+
"roleScopeTagIds": [
65+
"0"
66+
],
67+
"@odata.type": "#microsoft.graph.macOSCustomConfiguration",
68+
"deploymentChannel": "deviceChannel",
69+
"payloadName": "' + $FileName + '",
70+
"payloadFileName": "' + $file + '",
71+
"payload": "' + $payload + '"
72+
}'
73+
Write-Host $FileName -ForegroundColor Green
74+
75+
$uri = "https://graph.microsoft.com/beta/deviceManagement/deviceConfigurations"
76+
$graphAction = "POST"
77+
Invoke-MgGraphRequest -Uri $uri -Method $graphAction -Body $json -ContentType "application/json"
78+
Write-Host "Uploaded $FileName configuration" -ForegroundColor Cyan
79+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Add Defender Config Profiles to Intune
2+
This script is used to download the [mobileconfig files for Defender](https://github.com/microsoft/mdatp-xplat/tree/master/macos/mobileconfig/profiles) and add them to your Intune tenant.
3+
4+
## Script Settings
5+
This is a PowerShell script run from the console to get the [mobileconfig files for Defender](https://github.com/microsoft/mdatp-xplat/tree/master/macos/mobileconfig/profiles) and add them to your Intune tenant. You must have the Microsoft Graph PowerShell SDK installed. Run this command if you haven't installed it yet:
6+
7+
Install-Module Microsoft.Graph -Scope CurrentUser
8+
9+

0 commit comments

Comments
 (0)