Adds permissions for the VMId to all assigned disks.
.\Restore-VMPermission.ps1 [-VM] <String> [-WhatIf] [-Confirm] [<CommonParameters>]
This script uses the Hyper-V Module to update permissions for all assigned disks on one ore more VMs. This is useful if you move/replace VHDs and the read permission ACE for VMId is missing.
-VM <String> VM, specify the VM that needs permissions fixed. Required? true Position? 1 Default value Accept pipeline input? true (ByPropertyName) Accept wildcard characters? false -WhatIf [<SwitchParameter>] Required? false Position? named Default value Accept pipeline input? false Accept wildcard characters? false -Confirm [<SwitchParameter>] Required? false Position? named Default value Accept pipeline input? false Accept wildcard characters? false <CommonParameters> This cmdlet supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer, PipelineVariable, and OutVariable. For more information, see about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).
You can pipe objcets with a VMName property, such as returned by Get-VM, to this script.
None. This script does not write any objects to the pipeline.
PS C:\>Restore-VMPermission.ps1 -VM dc01
This example adds permission for dc01 VMId to the ACL of all assigned disks for dc01.
PS C:\>Get-VM | Restore-VMPermission.ps1
This example uses Get-VM to get all VMs on the local machine. It gets all disks for all VMs and adds the required premissions for VMId to the ACL.
Download & Source for Restore-VMPermission
I’ve published the Script to the PowerShell Gallery, you can install or download it using the following commands:
Install-Script -Name Restore-VMPermission -Scope CurrentUser
Save-Script -Name Restore-VMPermission -Path <Path>
And you can find the source in the following GitHub Repository: tomtorggler/PowerShell