VMware Cloud Community
Squigglymonkey
Enthusiast
Enthusiast
Jump to solution

inventory script help

I need an inventory of vms, (name, OS, OS version and installed software). I used a script that I got help with in this forum with getting the status of a service, and it is partially working.

$script = @"get-package -providername msi,programs|ft name, version"@
$report = Get-VM -Name (Get-Content -Path .\servers.txt) | %{
   Invoke-VMScript -VM $_ -ScriptText $script -ScriptType Powershell |
  select @{N='VM';E={$_.VM.Name}},@{N='Status';E={$_.ScriptOutput.Trim()}}}
$report | Export-Csv .\report.csv -NoTypeInformation -UseCulture
/endcode

I need to add the OS and OS version.
The output doesn't work well either.
It looks like this:

"VM","Status"
"test-server1","Name                                                               Version        
----                                                               -------        
McAfee Endpoint Security Threat Prevention                         10.7.0         
Local Administrator Password Solution                              6.0.1.0        
7-Zip 19.00 (x64)                                                  19.00          

There's more software titles, I truncated it.
I'd like it to be something like this:

"VM","Status","Configured OS","Name","version"
server-1,powered-on,Microsoft Windows Server 2016 or later (64-bit),McAfee Endpoint Security Threat Prevention,10.7.0         
server-1,powered-on,Microsoft Windows Server 2016 or later (64-bit),Local Administrator Password Solution,6.0.1.0        
server-1,powered-on,Microsoft Windows Server 2016 or later (64-bit),7-Zip 19.00 (x64),19.00
server-2,powered-off,,



Thank you!

 

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could try something like this

$script = @'
Get-Package -providername msi,Programs| Select Name,Version | Convertto-Csv -NoTypeInformation
'@

Get-VM -Name (Get-Content -Path .\servers.txt) -PipelineVariable vm |
ForEach-Object -Process {
    $result = Invoke-VMScript -VM $vm -ScriptText $script -ScriptType Powershell -GuestCredential $cred
    $result.ScriptOutput.Split("`n") | where{$_ -notmatch "Warning:"} | Convertfrom-Csv -Header Name,Version |
    Select @{N='VM';E={$VM.Name}},
        @{N='State';E={$vm.PowerState}},
        @{N='Configured OS';E={$vm.ExtensionData.Config.GuestFullName}},
        Name,Version
} |
Export-Csv .\report.csv -NoTypeInformation -UseCulture


 


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

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

You could try something like this

$script = @'
Get-Package -providername msi,Programs| Select Name,Version | Convertto-Csv -NoTypeInformation
'@

Get-VM -Name (Get-Content -Path .\servers.txt) -PipelineVariable vm |
ForEach-Object -Process {
    $result = Invoke-VMScript -VM $vm -ScriptText $script -ScriptType Powershell -GuestCredential $cred
    $result.ScriptOutput.Split("`n") | where{$_ -notmatch "Warning:"} | Convertfrom-Csv -Header Name,Version |
    Select @{N='VM';E={$VM.Name}},
        @{N='State';E={$vm.PowerState}},
        @{N='Configured OS';E={$vm.ExtensionData.Config.GuestFullName}},
        Name,Version
} |
Export-Csv .\report.csv -NoTypeInformation -UseCulture


 


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

0 Kudos
Squigglymonkey
Enthusiast
Enthusiast
Jump to solution

Oh my goodness, that was fast! Thank you. The output is perfect.

One thing made me think, instead of get-content, can it just be all the windows servers?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could try something like this instead

Get-VM -PipelineVariable vm | where{$_.ExtensionData.Config.GuestFullName -match "Windows"} |

  


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

0 Kudos