VMware Cloud Community
sabarirjpm
Contributor
Contributor
Jump to solution

Find if a process is running in the guest OS

Hi All

Am trying to find if a process is running in the guest OS. The guest OS is a mixture of Linux, Windows. Is there a way to do it using PowerCLI

 

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You mean something like this?


@sabarirjpm wrote:

Thanks @LucD . Can you help me to add the $vms.Name and the corresponding output of the Get-Process. 


$sInvoke = @{
        VM = $vms
        ScriptText = 'Get-Process -Name <processname> -ErrorAction Ignore'
        ScriptType = 'PowerShell'
        GuestCredential = $cred
}

Get-VM -PipelineVariable vm |
Where-Object { $_.PowerState -eq 'PoweredOn' -and $_.ExtensionData.Config.GuestFullName -match "Windows" } |
ForEach-Object -Process {
        $sInvoke.VM = $vm
        $result = Invoke-VMScript @sInvoke
        if($result.ScriptOutput.Length -eq 0){
                $found = $false
        }
        else{
                $found = $true
        }
        New-Object PSObject -Property ([ordered]@{
                VM = $vm.Name
                Found = $found
        })
}




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

View solution in original post

6 Replies
Macleud
Enthusiast
Enthusiast
Jump to solution

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

If your vSphere version and VMware Tools versions are on the correct level, you can use the AppInfo feature.
See William's post Application Discovery in vSphere with VMware Tools 11


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

Reply
0 Kudos
sabarirjpm
Contributor
Contributor
Jump to solution

Found few examples and tried the below

$vms = Get-VM | Where-Object { $_.PowerState -eq 'PoweredOn' -and $_.ExtensionData.Config.GuestFullName -match "Windows"}
$sInvoke = @{
    VM = $vms
    ScriptText = 'Get-Process -Name <processname> -ea Ignore'
    ScriptType = 'PowerShell'
    GuestCredential = $cred
}

$result = Invoke-VMScript @sInvoke
$result.ScriptOutput
 
Will the above work for me if the guest OS is Windows? I am getting the output. Can someone please help me in getting the VM Name along with the output

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, provided the VMware Tools are installed and the credentials are valid in the Guest OS


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

Reply
0 Kudos
sabarirjpm
Contributor
Contributor
Jump to solution

Thanks @LucD . Can you help me to add the $vms.Name and the corresponding output of the Get-Process. 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You mean something like this?


@sabarirjpm wrote:

Thanks @LucD . Can you help me to add the $vms.Name and the corresponding output of the Get-Process. 


$sInvoke = @{
        VM = $vms
        ScriptText = 'Get-Process -Name <processname> -ErrorAction Ignore'
        ScriptType = 'PowerShell'
        GuestCredential = $cred
}

Get-VM -PipelineVariable vm |
Where-Object { $_.PowerState -eq 'PoweredOn' -and $_.ExtensionData.Config.GuestFullName -match "Windows" } |
ForEach-Object -Process {
        $sInvoke.VM = $vm
        $result = Invoke-VMScript @sInvoke
        if($result.ScriptOutput.Length -eq 0){
                $found = $false
        }
        else{
                $found = $true
        }
        New-Object PSObject -Property ([ordered]@{
                VM = $vm.Name
                Found = $found
        })
}




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