Merge pull request #4318 from Tadas/fix-hyperv-admin
Check for 'Hyper-V Administrators' security group
This commit is contained in:
commit
c5ddbacb62
|
@ -64,7 +64,7 @@ func (d *HypervPS4Driver) Verify() error {
|
|||
return err
|
||||
}
|
||||
|
||||
if err := d.verifyElevatedMode(); err != nil {
|
||||
if err := d.verifyHypervPermissions(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -293,16 +293,28 @@ func (d *HypervPS4Driver) verifyPSHypervModule() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (d *HypervPS4Driver) verifyElevatedMode() error {
|
||||
func (d *HypervPS4Driver) verifyHypervPermissions() error {
|
||||
|
||||
log.Printf("Enter method: %s", "verifyElevatedMode")
|
||||
log.Printf("Enter method: %s", "verifyHypervPermissions")
|
||||
|
||||
hypervAdminCmd := "([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole('Hyper-V Administrators')"
|
||||
|
||||
var ps powershell.PowerShellCmd
|
||||
cmdOut, err := ps.Output(hypervAdminCmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
res := strings.TrimSpace(string(cmdOut))
|
||||
|
||||
if res == "False" {
|
||||
isAdmin, _ := powershell.IsCurrentUserAnAdministrator()
|
||||
|
||||
if !isAdmin {
|
||||
err := fmt.Errorf("%s", "Please restart your shell in elevated mode")
|
||||
err := fmt.Errorf("%s", "Current user is not a member of 'Hyper-V Administrators' or 'Administrators' group")
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue