Created
October 21, 2019 17:51
-
-
Save sgoley/33a3589d46fb2ff363897d0e294d6156 to your computer and use it in GitHub Desktop.
Update Microsoft Device Active Directory Name and Owner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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