dhanu2k7
Enthusiast
Enthusiast

runing script in guest OS

Hello


I have powershell script to get the list of application installed on the servers through get-itemproperty,, now i want to run this on all virtual machine through powerCLI, can you please help me?

Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |  Select DisplayName, DisplayVersion, InstallDate,PSComputerName  |?{$_.DisplayName -like "VMware Tools" -or $_.DisplayName -like "IBM Tivoli Monitoring" -or $_.DisplayName -like "Symantec Endpoint Protection" -or $_.DisplayName -like "ILMT-TAD4D Agent" -or $_.DisplayName -like "IBM BigFix Client" -or $_.DisplayName -like "IBM Tivoli Storage Manager Client" | select -ExcludeProperty RunspaceId }} | ForEach-Object { $D += $_ }

Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*  | Select  DisplayName, DisplayVersion,InstallDate,PSComputerName| ?{$_.DisplayName -like "VMware Tools" -or $_.DisplayName -like "IBM Tivoli Monitoring" -or $_.DisplayName -like "Symantec Endpoint Protection" -or $_.DisplayName -like "ILMT-TAD4D Agent" -or $_.DisplayName -like "IBM BigFix Client" -or $_.DisplayName -like "IBM Tivoli Storage Manager Client"

Tags (2)
0 Kudos
5 Replies
LucD
Leadership
Leadership

You can use the Invoke-VMScript cmdlet to run a PowerShell script inside the guest OS (use the -ScriptType PowerShell parameter)

The VM needs to have VMware Tools installed.


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

0 Kudos
dhanu2k7
Enthusiast
Enthusiast

if I use invoke-vmscript, does it cause any issue on VM?  cause its running very slow if I run it on all the server

0 Kudos
LucD
Leadership
Leadership

Not sure what you mean by "issue on VM".

What is slow, the VM globally, or the script running inside the guest OS of the VM?

Note that there is a bit of overhead for running a script inside the guest OS.

The results might not return as fast as if you run them locally.


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

0 Kudos
dhanu2k7
Enthusiast
Enthusiast

$Sinfo=@()

$user= Get-Credential supplier.coop\in05750m

Get-VM gb02qdc412cpkwm| ForEach-Object {

    $VM = $_

$Report = "" | Select-Object VMname,displayname1,displayname2,displayversion1,displayversion2

$Report.VMName = $VM.name

$Report.displayname1=Invoke-VMScript -VM $VM -GuestCredential $user -scripttype Powershell -scripttext {Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |  Select-object DisplayName |?{$_.DisplayName -like "VMware Tools" -or $_.DisplayName -like "IBM Tivoli Monitoring" -or $_.DisplayName -like "Symantec Endpoint Protection" -or $_.DisplayName -like "ILMT-TAD4D Agent" -or $_.DisplayName -like "IBM BigFix Client" -or $_.DisplayName -like "IBM Tivoli Storage Manager Client" }}

$Report.displayname2=Invoke-VMScript -VM $VM -GuestCredential $user -scripttype Powershell -scripttext {Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*  | Select-object  DisplayName| ?{$_.DisplayName -like "VMware Tools" -or $_.DisplayName -like "IBM Tivoli Monitoring" -or $_.DisplayName -like "Symantec Endpoint Protection" -or $_.DisplayName -like "ILMT-TAD4D Agent" -or $_.DisplayName -like "IBM BigFix Client" -or $_.DisplayName -like "IBM Tivoli Storage Manager Client" }}

$Report.displayversion1=Invoke-VMScript -VM $VM -GuestCredential $user -scripttype Powershell -scripttext {Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |  Select-object * |?{$_.DisplayName -like "VMware Tools" -or $_.DisplayName -like "IBM Tivoli Monitoring" -or $_.DisplayName -like "Symantec Endpoint Protection" -or $_.DisplayName -like "ILMT-TAD4D Agent" -or $_.DisplayName -like "IBM BigFix Client" -or $_.DisplayName -like "IBM Tivoli Storage Manager Client" }}

$Report.displayversion2=Invoke-VMScript -VM $VM -GuestCredential $user -scripttype Powershell -scripttext {Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*  | Select-object * | ?{$_.DisplayName -like "VMware Tools" -or $_.DisplayName -like "IBM Tivoli Monitoring" -or $_.DisplayName -like "Symantec Endpoint Protection" -or $_.DisplayName -like "ILMT-TAD4D Agent" -or $_.DisplayName -like "IBM BigFix Client" -or $_.DisplayName -like "IBM Tivoli Storage Manager Client" }}

$Sinfo+=$Report

}

$Sinfo | export-csv ff.csv  -NoTypeInformation -useculture

I have few question

1. If I use vm-invokescript, does it impact VM performance as output i am getting slow compare to what i run through powershell

2. above script not giving proper output in csv.. i would like to see  something like below

powershell.jpg

0 Kudos
LucD
Leadership
Leadership

The object that is returned by the Invoke-VMScript cmdlet has a property named ScriptOutput

In that property you'll find the output from your script.


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

0 Kudos