דלג לתוכן

Script for Updating Device Ownership in Microsoft Graph

תוכן זה אינו זמין עדיין בשפה שלך.

This script connects to Microsoft Graph with the appropriate permissions and performs the following tasks:

  1. Connects to Microsoft Graph: The script uses Connect-MgGraph with the DeviceManagementManagedDevices.ReadWrite.All scope to authenticate and access device management data.
  2. Filters Devices: Retrieves devices that are running either macOS or Windows and are owned by personal users.
  3. Updates Device Ownership: Loops through the filtered devices and updates the ownership type from “personal” to “company” using the Update-MgDeviceManagementManagedDevice cmdlet.

Here is the Script:

Connect-MgGraph -Scopes “DeviceManagementManagedDevices.ReadWrite.All”  Get-MgDeviceManagementManagedDevice |  Where-Object {($.OperatingSystem -EQ “macOS”) -or ($.OperatingSystem -EQ “Windows”)}|  Where-Object ManagedDeviceOwnerType -EQ “personal” |  ForEach-Object {Update-MgDeviceManagementManagedDevice -ManagedDeviceId $_.Id -ManagedDeviceOwnerType “company” }