Skip to content

Commit 1bdd04c

Browse files
author
William Lam
committed
Updated to support Container App Discovery with VMware Tools 12
1 parent 5401bb8 commit 1bdd04c

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

powershell/VMApplicationInfo.ps1

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,55 @@ Function Get-VMApplicationInfo {
5353
}
5454
}
5555
}
56+
57+
Function Get-VMContainerInfo {
58+
<#
59+
.DESCRIPTION Retrieves container applications running inside of a VM
60+
.NOTES Author: William Lam
61+
.NOTES Site: www.williamlam.com
62+
.NOTES Reference: https://williamlam.com/2022/03/enhancements-to-vmware-tools-12-for-container-discovery-in-vsphere.html
63+
.PARAMETER VM
64+
VM Object
65+
.PARAMETER Output
66+
CSV or JSON output file
67+
.EXAMPLE
68+
Get-VMContainerInfo -VM (Get-VM "VMware-Event-Broker-Appliance")
69+
.EXAMPLE
70+
Get-VMContainerInfo -VM (Get-VM "VMware-Event-Broker-Appliance") -Output CSV
71+
.EXAMPLE
72+
Get-VMContainerInfo -VM (Get-VM "VMware-Event-Broker-Appliance") -Output JSON
73+
#>
74+
param(
75+
[Parameter(Mandatory=$true)]$VM,
76+
[Parameter(Mandatory=$false)][ValidateSet("CSV","JSON")][String]$Output
77+
)
78+
79+
$containerInfoValue = (Get-AdvancedSetting -Entity $VM -Name "guestinfo.vmtools.containerinfo").Value
80+
81+
if($containerInfoValue -eq $null) {
82+
Write-Host "Application Discovery may not been enabled for this VM or is not running VMware Tools 12"
83+
} else {
84+
$containerInfo = $containerInfoValue | ConvertFrom-Json
85+
$containerUpdateVersion = $containerInfo.updateCounter
86+
$containerKey = ($containerInfo.containerinfo | Get-Member -MemberType NoteProperty).name
87+
88+
$results = $containerInfo.containerinfo.$containerKey.i | Sort-Object
89+
90+
Write-Verbose "Container Discovery Time: $($containerInfo.publishTime)"
91+
if($Output -eq "CSV") {
92+
$fileOutputName = "$($VM.name)-version-$($containerUpdateVersion)-apps.csv"
93+
94+
Write-Host "`tSaving output to $fileOutputName"
95+
($containerInfo.containerinfo.$containerKey.i) | ForEach {
96+
[PSCustomObject]@{Container = $_}
97+
} | ConvertTo-Csv | Out-File -FilePath "$fileOutputName"
98+
} elseif ($Output -eq "JSON") {
99+
$fileOutputName = "$($VM.name)-version-$($containerUpdateVersion)-apps.json"
100+
101+
Write-Host "`tSaving output to $fileOutputName"
102+
($containerInfo.containerinfo.$containerKey.i) | ConvertTo-Json | Out-File -FilePath "$fileOutputName"
103+
} else {
104+
$results
105+
}
106+
}
107+
}

0 commit comments

Comments
 (0)