VMware Cloud Community
NucleusVM
Enthusiast
Enthusiast
Jump to solution

check if a service exists on a vmguest, using powercli

Is there a way I can check if a service exists on a vmguest, using powercli?

I found many ways to do this using powershell commands, but I want to know if I can do it using powercli.

Thanks

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

If you have the VMware Tools installed on the VMs, you can use the Invoke-VMScript cmdlet to launch a PowerShell script inside the guest OS.

$vm = Get-VM -Name MyVM

$cmd = "Get-Service -Name WinRM"

Invoke-VMScript -VM $vm -ScriptText $cmd

Depending on the account under which you run the script, you might have to use the GuestCredential parameter


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

3 Replies
LucD
Leadership
Leadership
Jump to solution

If you have the VMware Tools installed on the VMs, you can use the Invoke-VMScript cmdlet to launch a PowerShell script inside the guest OS.

$vm = Get-VM -Name MyVM

$cmd = "Get-Service -Name WinRM"

Invoke-VMScript -VM $vm -ScriptText $cmd

Depending on the account under which you run the script, you might have to use the GuestCredential parameter


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

jpsider
Expert
Expert
Jump to solution

Here is a slightly different way, and adding the guest credentials

$vm = get-vm -Name MyVM

$cmd = "sc query <servicename>"

$GuestUsername = "guestUN"

$GuestPassword = "GuestPWD"

Invoke-VMScript -VM $VM -ScriptText $cmd -GuestUser $GuestUsername -GuestPassword $GuestPassword

0 Kudos
chiisaryuu
Enthusiast
Enthusiast
Jump to solution

I do this away:

Get-Service -ComputerName (Get-View -id (Get-VM VMNAME).Id).guest.hostname

Bye.

0 Kudos