Skip to content

Commit

Permalink
simplify the checking for user part of the hyperv admins group
Browse files Browse the repository at this point in the history
we don't need to convert the SID to a group name since the Add-LocalGroupMember
cmdlet has a -SID flag which can directly use the SID of the hyperv admin group
to add a member to it
  • Loading branch information
anjannath authored and openshift-merge-robot committed Jan 18, 2023
1 parent 47f3a68 commit c98dca9
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions pkg/crc/preflight/preflight_checks_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,7 @@ func checkIfUserPartOfHyperVAdmins() error {
}

func fixUserPartOfHyperVAdmins() error {
outGroupName, _, err := powershell.Execute(`(New-Object System.Security.Principal.SecurityIdentifier("S-1-5-32-578")).Translate([System.Security.Principal.NTAccount]).Value`)
if err != nil {
logging.Debug(err.Error())
return fmt.Errorf("Unable to get group name")
}
groupName := strings.TrimSpace(strings.ReplaceAll(strings.TrimSpace(outGroupName), "BUILTIN\\", ""))

_, _, err = powershell.ExecuteAsAdmin("adding current user to Hyper-V administrator group", fmt.Sprintf("Add-LocalGroupMember -Group '%s' -Member '%s'", groupName, username()))
_, _, err := powershell.ExecuteAsAdmin("adding current user to Hyper-V administrator group", fmt.Sprintf("Add-LocalGroupMember -SID 'S-1-5-32-578' -Member '%s'", username()))
if err != nil {
return err
}
Expand Down

0 comments on commit c98dca9

Please sign in to comment.