-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet VMs DeviceHotplug.ps1
More file actions
38 lines (30 loc) · 1.42 KB
/
Get VMs DeviceHotplug.ps1
File metadata and controls
38 lines (30 loc) · 1.42 KB
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
#######################################################################
# vCenter VM devices.hotplug Report
#######################################################################
# Author(s): Corey Blaz & Michael Gorka
# Github: https://github.com/blazcode
# Web: https://vcorey.com
# Connect to vCenter
$creds = Get-Credential
Connect-VIServer -Server vcsa-8x.corp.local -Credential $creds -Force
# Create output variable
$output = @()
# Get all VMs and iterate through them, searching for devices.hotplug
Foreach ($VM in Get-VM) {
Write-Host "Checking: " $VM.name
# Get-AdvancedSetting returns nothing at all if setting is unset, therefore must set to $null and update the value if the setting is configured
$devicesHotplugSetting = $null
$devicesHotplugSetting = $(Get-AdvancedSetting -Entity $VM -Name "devices.hotplug").Value
if ($devicesHotplugSetting -ne $null) {
$devicesHotplugValue = $devicesHotplugSetting
} else {
$devicesHotplugValue = "UNSET"
}
$vmObject = New-Object -TypeName PSObject
$vmObject | Add-Member -MemberType NoteProperty -Name 'Name' -Value $VM.name
$vmObject | Add-Member -MemberType NoteProperty -Name 'devicesHotplug' -Value $devicesHotplugValue
$output += $vmObject
}
# This can be exported to .csv
$output | sort -Property devicesHotplug -Descending | Format-Table
$output | Export-Csv -Path C:\temp\report.csv -NoTypeInformation