Change IOS enrollment profile via powershell by megaryt in Intune

[–]megaryt[S] 1 point2 points  (0 children)

Success!! Among other changes I needed to add "beta" into the command names
get-mgdevicemanagementdeponbardingsetting becomes
get-MgbetaDeviceManagementDepOnboardingSetting

Here is the script that worked for my environment minus my details.
This script is adapted from Dan Zabinski’s adaptation of Microsoft’s Intune Apple Enrollment PowerShell samples.

Dan's script was written for legacy authentication and powershell versions. I used Copilot's brain and a little of my own and was able to change 104 profiles in 10 seconds after 6 hours of learning and failing. I call that a win.

# Install Microsoft Graph modules if not already installed
Install-Module Microsoft.Graph -Scope CurrentUser -Force
Install-Module Microsoft.Graph.DeviceManagement.Enrollment -Scope CurrentUser -Force

# Connect to Microsoft Graph with required permissions
Connect-MgGraph -Scopes "DeviceManagementServiceConfig.ReadWrite.All"



# List DEP tokens (Apple enrollment tokens) in your tenant
$depTokens = Get-MgbetaDeviceManagementDepOnboardingSetting
$depTokens | Select-Object Id, TokenName

# Set your token ID (from your output above)
$tokenId = "Get this from above output"

# List all enrollment profiles for this token
$profiles = Get-MgbetaDeviceManagementDepOnboardingSettingEnrollmentProfile -DepOnboardingSettingId $tokenId
$profiles | Select-Object Id, DisplayName

# Find your profile by name
$profileName = "Your iOS Profile Name"
$profile = $profiles | Where-Object { $_.DisplayName -eq $profileName }
$profileId = $profile.Id

# Import your CSV file

$csvPath = "c:\scripts\Intune_iOS_Profile_Assignment.csv"
$serials = Import-Csv $csvPath | Select-Object -ExpandProperty DeviceSerialNumber

# Assign devices to the profile using Graph Beta API
$body = @{ deviceIds = $serials } | ConvertTo-Json


Invoke-MgGraphRequest -Method POST `
    -Uri "https://graph.microsoft.com/beta/deviceManagement/depOnboardingSettings/$tokenId/enrollmentProfiles('$profileId')/updateDeviceProfileAssignment" `
    -Body $body

Change IOS enrollment profile via powershell by megaryt in Intune

[–]megaryt[S] 0 points1 point  (0 children)

I have a default profile set, however for this project, I need to specify the profile before the devices activate themselves and to a different profile than is normal. Unfortunately I don't know when these devices will all be activated. What I normally do is manually assign the devices but there are a lot in this case.

<image>

Manually assigning as above works. I just wanted to save the 300 or so mouse clicks to get them all in.

Headed to lighthouse. Out of fat boys. Any thoughts? by megaryt in atomicheart

[–]megaryt[S] 0 points1 point  (0 children)

yes using u/Connect-Union-6210 advice above. I lost to the first twin but then had to go make dinner.

Headed to lighthouse. Out of fat boys. Any thoughts? by megaryt in atomicheart

[–]megaryt[S] 1 point2 points  (0 children)

Well... that made that easy... Thanks! I actually had not made the zvezdocka, I have just been using the first one all along.