-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGet-EsxCliVib.ps1
149 lines (125 loc) · 4.15 KB
/
Get-EsxCliVib.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<#
.SYNOPSIS
Get details on a specific ESXi VIB
.DESCRIPTION
Get details on a specific ESXi VIB.
This can be usefule if you are looking for version information about a given package on an ESXi host.
This script/function is best utilized when sending a host object to it via the pipeline; see examples for more detail.
.INPUTS
VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl
.PARAMETER VMHost
Name of ESXi host
.PARAMETER VIBName
Name of vib package you wish to query detail for
.EXAMPLE
PS C:\> Get-VMHost | .\Get-EsxCliVib -VIBName hp-ams
.EXAMPLE
PS C:\> Get-VMHost esxihost01.company.com | .\Get-EsxCliVib -VIBName hp-ams
Host : esxihost01.company.com
Name : hp-ams
Version : 550.10.0.1-07.1198610
Vendor : Hewlett-Packard
InstallDate : 2014-10-03
ID : Hewlett-Packard_bootbank_hp-ams_550.10.0.1-07.1198610
CreationDate : 2014-09-09
Status :
HostVersion : 5.5.0
HostVersionBuild : 1892794
HostMfg : HP
HostModel : ProLiant BL460c Gen8
.NOTES
#TAG:PUBLIC
GitHub: https://github.com/vScripter
Twitter: @vScripter
Email: kevin@vMotioned.com
[-------------------------------------DISCLAIMER-------------------------------------]
All script are provided as-is with no implicit
warranty or support. It's always considered a best practice
to test scripts in a DEV/TEST environment, before running them
in production. In other words, I will not be held accountable
if one of my scripts is responsible for an RGE (Resume Generating Event).
If you have questions or issues, please reach out/report them on
my GitHub page. Thanks for your support!
[-------------------------------------DISCLAIMER-------------------------------------]
.LINK
https://github.com/vScripter
#>
[CmdletBinding(DefaultParameterSetName = 'Default',
PositionalBinding = $true)]
param
(
[Parameter(ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true,
Position = 0)]
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl]$VMHost,
[Parameter(Mandatory = $true,
ValueFromPipeline = $false,
ValueFromPipelineByPropertyName = $false,
Position = 1)]
[string]$VIBName
)
BEGIN {
#Requires -Version 3
# clear/set final $result variable
$result = @()
} # BEGIN
PROCESS {
try {
Write-Verbose -Message "Working on $($_.Name)..."
# Clear/set variables
$esxcli = $null
$softwareList = $null
# Assign vmhost query objects to a variable to be called later
$esxcli = Get-EsxCli -VMHost $VMHost
$softwareList = $esxcli.software.vib.list() | Where-Object { $_.Name -like "$VIBName" }
# get uptime details
$bootTime = ($VMHost | Get-View).runtime.boottime
$calcUptime = ((Get-Date) - $bootTime)
# Create custom object to store host/vib information
$objHpVib = [PSCustomObject] @{
Host = $_.Name
VibName = $softwareList.Name
VibVersion = $softwareList.Version
VibVendor = $softwareList.Vendor
VibInstallDate = $softwareList.InstallDate
VibID = $softwareList.ID
VibCreationDate = $softwareList.CreationDate
VibStatus = $softwareList.Status
HostUptimeDays = $calcUptime.Days
HostVersion = $_.Version
HostVersionBuild = $_.Build
HostMfg = $_.Manufacturer
HostModel = $_.Model
Status = $null
} # $objHpVib
# Send collection detail for current object to the final $result variable
$result += $objHpVib
} catch {
Write-Warning -Message "Error gathering detail from $VMHost"
# clear/set the $colError array
$colError = @()
# create new object to store error detail
$objError = [PSCustomObject] @{
Host = $_.Name
VibName = $null
VibVersion = $null
VibVendor = $null
VibInstallDate = $null
VibID = $null
VibCreationDate = $null
VibStatus = $null
HostUptimeDays = $null
HostVersion = $null
HostVersionBuild = $null
HostMfg = $null
HostModel = $null
Status = "$_"
} # $objError
# send collection detail to final $result variable
$result += $objError
} # try/catch
} # PROCESS
END {
# call final result - output from the console can be formatted using regular export cmdlets (Export-Csv; Out-Gridview; Format-Table; etc.)
$result
} # END