@@ -53,3 +53,55 @@ Function Get-VMApplicationInfo {
53
53
}
54
54
}
55
55
}
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 " `t Saving 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 " `t Saving output to $fileOutputName "
102
+ ($containerInfo.containerinfo .$containerKey.i ) | ConvertTo-Json | Out-File - FilePath " $fileOutputName "
103
+ } else {
104
+ $results
105
+ }
106
+ }
107
+ }
0 commit comments