In your environment where you manage the Hyper-V/VMM section or work with it, you might come across times when you cannot update a Virtual Machine or change it’s properties because the Owner who managed it has left and the account was deleted and now you have an “S-XXX-XX” account listed next to the owner.
Another scenario might be that you want to standardize the Owner for all machines, if you have several hundred or thousands of machines, doing this one by one will take you days or maybe weeks.
Well, again, PowerShell to the rescue to change this all for you with these few commands.
Firstly we need to get some information on the Administrator User on VMM, to do this run the following command:
- Get-SCUserRole -VMMServer localhost -Name Administrator
What we need here is the ID which is required for the next command:
- $UserRole = Get-SCUserRole -VMMServer localhost -Name “Administrator” -ID “75700cd5-XXX-XXXX”
- Get-VM -VMMServer “VMM Server” | where {$_.Owner -eq “domain\User”} | Set-VM -Owner “domain\user” -UserRole $UserRole
With the first command, input the ID you get from the first command we ran.
In the second command, update the Owner with the current Owner details and when you set it in the second part of the command, put in the new users information.
If you run into a situation where the User is blank then you can use the command below:
- $UserRole = Get-SCUserRole -VMMServer localhost -Name “Administrator” -ID “75700cd5-XXX-XXXX”
- Get-VM -VMMServer “VMM Server” | where {$_.Owner -eq $Null} | Set-VM -Owner “domain\user” -UserRole $UserRole
If you have it where the User is unknown then you can run the following command:
- $UserRole = Get-SCUserRole -VMMServer localhost -Name “Administrator” -ID “75700cd5-XXX-XXXX”
- Get-VM -VMMServer “VMM Server” | where {$_.Owner -eq “Unknown”} | Set-VM -Owner “domain\user” -UserRole $UserRole
Depending on the size of your environment, this will take a few minutes to update and you can watch it in VMM or keep an eye on the Job list in VMM as well.
Hope it helps.