Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Executing file on windows vm using govc #2446

Closed
rahul14sep opened this issue May 19, 2021 · 6 comments · Fixed by #2451
Closed

Executing file on windows vm using govc #2446

rahul14sep opened this issue May 19, 2021 · 6 comments · Fixed by #2451

Comments

@rahul14sep
Copy link

rahul14sep commented May 19, 2021

I want to execute powershell script on window vm using govc, I tried using govc guest.run but it looks to execute file in /bin/bash shell, Is there any way i could tell govc to use windows command prompt?

Command I tried
govc guest.run -vm VC-ATM-ICLONE -l='username:password' 'powershell C:\windows_network_refresh.ps1'

and got below error
govc: ServerFaultCode: File /bin/bash was not found

Is there any other way I could execute file on windows vm.

@github-actions
Copy link
Contributor

Howdy 🖐   rahul14sep ! Thank you for your interest in this project. We value your feedback and will respond soon.

If you want to contribute to this project, please make yourself familiar with the CONTRIBUTION guidelines.

@dougm
Copy link
Member

dougm commented May 19, 2021

What does the following report for your vm?

% govc object.collect vm/VC-ATM-ICLONE guest.guestFamily

The govc code uses cmd.exe when windowsGuest, otherwise bash:

switch c.GuestFamily {
case types.VirtualMachineGuestOsFamilyWindowsGuest:
// Using 'cmd.exe /c' is required on Windows for i/o redirection
path = "c:\\Windows\\System32\\cmd.exe"
args = append([]string{"/c", cmd.Path}, args...)
default:
if !strings.ContainsAny(cmd.Path, "/") {
// vmware-tools requires an absolute ProgramPath
// Default to 'bash -c' as a convenience
path = "/bin/bash"
arg := "'" + strings.Join(append([]string{cmd.Path}, args...), " ") + "'"
args = []string{"-c", arg}
}
}

@rahul14sep
Copy link
Author

govc object.collect vm/VC-ATM-ICLONE guest
Output:
guest.toolsStatus types.VirtualMachineToolsStatus toolsOk
guest.toolsVersionStatus string guestToolsCurrent
guest.toolsVersionStatus2 string guestToolsSupportedNew
guest.toolsRunningStatus string guestToolsRunning
guest.toolsVersion string 11269
guest.toolsInstallType string guestToolsTypeMSI
guest.guestId string
guest.guestFamily string otherGuestFamily
guest.guestFullName string Windows Server 2019, 64-bit (Build 17763)

Its not populating correct information for guest family because we are using ESX 6.7 which does not support win2k19 OS.

For such cases can we have optional parameter in guest.run to override shell path , where we could specify which
shell to use (shell="c:\Windows\System32\cmd.exe" or shell="/bin/bash") something like that .

Like we have option in pyvmomi
ps = vim.vm.guest.ProcessManager.ProgramSpec(programPath=r'C:\Windows\System32\cmd.exe', arguments='/c powershell C:\windows_network_refresh.ps1')

dougm added a commit to dougm/govmomi that referenced this issue May 20, 2021
@dougm dougm added this to the 0.26 milestone May 20, 2021
@dougm
Copy link
Member

dougm commented May 20, 2021

Ah ok. With #2451 you can use the same ProgramSpec in your example or the new guest.run -w flag to set guestFamily to Windows, which makes cmd.exe /c the default way to run the program

@rahul14sep
Copy link
Author

This will help. Thanks @dougm for adding this support.

dougm added a commit to dougm/govmomi that referenced this issue May 23, 2021
- Default to Windows family when family is "Other" and toolsInstallType is MSI

Fixes vmware#2446
dougm added a commit to dougm/govmomi that referenced this issue May 24, 2021
- Default to Windows family when family is "Other" and toolsInstallType is MSI

Fixes vmware#2446
dougm added a commit to dougm/govmomi that referenced this issue May 24, 2021
- Default to Windows family when family is "Other" and toolsInstallType is MSI

Fixes vmware#2446
@embano1
Copy link
Contributor

embano1 commented May 25, 2021

@rahul14sep just note that Doug created an even better fix for this issue using auto-detection, that is not requiring any flags :)

protochron pushed a commit to protochron/govmomi that referenced this issue Aug 31, 2021
- Default to Windows family when family is "Other" and toolsInstallType is MSI

Fixes vmware#2446
yuyin002 pushed a commit to yuyin002/govmomi that referenced this issue Jan 12, 2022
- Default to Windows family when family is "Other" and toolsInstallType is MSI

Fixes vmware#2446
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants