1
+ Function Get-VMApplicationInfo {
2
+ <#
3
+ .DESCRIPTION Retrieves discovered applications running inside of a VM
4
+ .NOTES Author: William Lam
5
+ .NOTES Site: www.virtuallyghetto.com
6
+ .NOTES Reference: http://www.virtuallyghetto.com/2019/12/application-discovery-in-vsphere-with-vmware-tools-11.html
7
+ . PARAMETER VM
8
+ VM Object
9
+ . PARAMETER Output
10
+ CSV or JSON output file
11
+ . EXAMPLE
12
+ Get-VMApplicationInfo -VM (Get-VM "DC-01")
13
+ . EXAMPLE
14
+ Get-VMApplicationInfo -VM (Get-VM "DC-01") -Output CSV
15
+ . EXAMPLE
16
+ Get-VMApplicationInfo -VM (Get-VM "DC-01") -Output JSON
17
+ #>
18
+ param (
19
+ [Parameter (Mandatory = $true )]$VM ,
20
+ [Parameter (Mandatory = $false )][ValidateSet (" CSV" , " JSON" )][String ]$Output
21
+ )
22
+
23
+ $appInfoValue = (Get-AdvancedSetting - Entity $VM - Name " guestinfo.appInfo" ).Value
24
+
25
+ if ($appInfoValue -eq $null ) {
26
+ Write-Host " Application Discovery has not been enabled for this VM"
27
+ } else {
28
+ $appInfo = $appInfoValue | ConvertFrom-Json
29
+ $appUpdateVersion = $appInfo.updateCounter
30
+
31
+ $results = $appInfo.applications | Sort-Object - Property a | FT @ {Name = " Application" ;e = {$_.a }}, @ {Name = " Version" ;e = {$_.v }}
32
+
33
+ Write-host - ForegroundColor Green " Application Discovery Time: $ ( $appInfo.publishTime ) "
34
+ if ($Output -eq " CSV" ) {
35
+ $fileOutputName = " $ ( $VM.name ) -version-$ ( $appUpdateVersion ) -apps.csv"
36
+
37
+ Write-Host " `t Saving output to $fileOutputName "
38
+ ($appInfo.applications ) | ConvertTo-Csv | Out-File - FilePath " $fileOutputName "
39
+ } elseif ($Output -eq " JSON" ) {
40
+ $fileOutputName = " $ ( $VM.name ) -version-$ ( $appUpdateVersion ) -apps.json"
41
+
42
+ Write-Host " `t Saving output to $fileOutputName "
43
+ ($appInfo.applications ) | ConvertTo-Json | Out-File - FilePath " $fileOutputName "
44
+ } else {
45
+ $results
46
+ }
47
+ }
48
+ }
0 commit comments