Skip to content

Instantly share code, notes, and snippets.

@techdecline
Last active December 26, 2019 13:57
Show Gist options
  • Save techdecline/24570399dc89db6c854a3dcaa5a613f7 to your computer and use it in GitHub Desktop.
Save techdecline/24570399dc89db6c854a3dcaa5a613f7 to your computer and use it in GitHub Desktop.
<#
This script allows modification of local MDM policies.
It is based on Microsoft Documentation: https://docs.microsoft.com/en-us/windows/client-management/mdm/using-powershell-scripting-with-the-wmi-bridge-provider
Author: Cornelius Schuchardt, SoftEd Systems GmbH
Must be executed using SYSTEM account.
#>
$namespaceName = "root\cimv2\mdm\dmmap"
$className = "MDM_Policy_Config01_Connectivity02"
$instance = "Connectivity"
$property = "AllowBluetooth"
$value = 0
# Enumerate all instances available for classname
$obj = Get-CimInstance -Namespace $namespaceName -ClassName $className
if (-not ($obj)) {
New-CimInstance -Namespace $namespaceName -ClassName $className -Property @{ParentID="./Vendor/MSFT/Policy/Config";InstanceID=$instance;$property=0}
}
else {
$currentValue = $obj.$property
if ($currentValue -eq $value) {
Write-Verbose "MDM setting is in consistent state: $property is $value"
}
else {
Write-Verbose "MDM setting must be changed: $property is $currentValue; Should be $value"
$obj.$property=$value
Set-CimInstance -CimInstance $obj
}
}
@leochou0729
Copy link

Very useful script. It seems to only work on Windows 10. Do you know how to do the same thing on Windows 7 & 8? Thanks!

@techdecline
Copy link
Author

Windows 7 will require a complete different approach as the MDM Providers do not exist. For Windows 8, there is probably another Configuration Service Provider. You could dig in using WMI Explorer and search for Bluetooth on a test device in the relevant namespace (root\cimv2\mdm\dmmap).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment