Bulk Intune IOS Content Filter

I had a requirement to block a list of URLs utilizing IOS content filter. I realized the Intune management UI does not have a upload button.

Please see below for the Powershell code. Please have an existing content filter in the policy. This will not create it.

##Connect to MSGraph
Connect-MSGraph -PSCredential $cred

#GET List of Sites
$BlockList = [string[]](Get-Content c:\temp\weblist.txt)

#Get the Policy we want to update
$Pol = Get-IntuneDeviceConfigurationPolicy | ? DisplayName -eq  "iOS MDM Corporate Features"

#The content filter settings are only in MS Graph Beta, so lets get that version
$URL = $pol.iosDeviceFeaturesConfigurationReferenceUrl -replace "v1.0","beta"
$PolBeta = Invoke-MSGraphRequest -Url $URL

#Create a copy of the filter and add our URLs
$ContentFilter = $PolBeta.contentFilterSettings
$ContentFilter.blockedUrls = $BlockList

#Create our iosDeviceFeaturesConfiguration Shell with the new contentFilter settings
$IOSF = @{
    '@odata.type' = '#microsoft.graph.iosDeviceFeaturesConfiguration' ;
    contentFilterSettings = $ContentFilter
}

#Patch the policy with new config.
Invoke-MSGraphRequest -Url $URL -HttpMethod PATCH -Content $($($IOSF | ConvertTo-Json) -replace "`r`n","" -replace " ","") -Verbose

A little background:

We are using the Microsoft.Graph.Intune PS modules. The contentFilterSettings only exist in the MS Graph beta; I had to get creative to update the policy.