Skip to content

Instantly share code, notes, and snippets.

@sgoley
Created October 21, 2019 17:51
Show Gist options
  • Save sgoley/33a3589d46fb2ff363897d0e294d6156 to your computer and use it in GitHub Desktop.
Save sgoley/33a3589d46fb2ff363897d0e294d6156 to your computer and use it in GitHub Desktop.
Update Microsoft Device Active Directory Name and Owner
$deviceName = 'myDeviceName' # configure device name
$newOwner = 'user@example.com' # login name of the new user
Connect-AzureAD
# Get-AzureADDevice # if you want to list all devices
# Get-AzureADUser # if you want to list all users
$device = Get-AzureADDevice | where { $_.DisplayName -eq $deviceName }
$aduser = Get-AzureADUser | where { $_.UserPrincipalName -eq $newOwner }
$oldowner = (Get-AzureADDeviceRegisteredOwner -ObjectId $device.ObjectId).ObjectId
"Change owner of device " + $device.DisplayName + " to " + $aduser.DisplayName
Add-AzureADDeviceRegisteredOwner -ObjectId $device.ObjectId -RefObjectId $aduser.ObjectId # add the new owner
Remove-AzureADDeviceRegisteredOwner -ObjectId $device.ObjectId -OwnerId $oldowner # remove the previous owner
Get-AzureADDeviceRegisteredOwner -ObjectId $device.ObjectId
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment