Cluster Audit PowerCLI One Liners (mostly)

All the commands below reference variables created from my menu system post, obviously if you are not using that menu you will need to change them to work with your environment.
These are just some of the commands i used recently on an audit:

To Export to CSV simply append the following to the end of the command
| sort created | export-csv -path "$Global:FilePath\$global:CLUChoice Snapshots $(get-date -f yyyy-MM-dd-hhmm).csv" -NoTypeInformation

List all Snapshots on this cluster
Get-Datacenter $global:DCChoice | Get-Cluster $global:CLUChoice | get-vm | get-snapshot | select vm, name, description, created, sizegb | sort created | ft

List all VMs on this cluster
Get-Datacenter $global:DCChoice | Get-Cluster $global:CLUChoice | get-vm | select Name, NumCpu, MemoryMB, VMHost, UsedSpaceGB, ProvisionedSpaceGB, Notes | ft

List hosts in this cluster
Get-Datacenter $global:DCChoice | Get-Cluster $global:CLUChoice | get-VMHost | Select Parent, Name, Version, Build, ConnectionState, PowerState, Model, ProcessorType, HyperthreadingActive, NumCpu, CpuTotalMhz, CpuUsageMhz, MemoryUsageGB, MemoryTotalGB | ft

List Cluster Configuration
Get-Datacenter $global:DCChoice | Get-Cluster $global:CLUChoice | select Name, VsanEnabled, DrsEnabled, DrsAutomationLevel, HAEnabled, HAAdmissionControlEnabled, VMSwapfilePolicy, EVCMode | ft

List Datastores
Get-Datacenter $global:DCChoice | Get-Cluster $global:CLUChoice | Get-Datastore | Select Datacenter, Name, Type, CapacityGB, FreeSpaceGB, State | ft

List LUNs
Get-Datacenter $global:DCChoice | Get-Cluster $global:CLUChoice | get-vmhost | Get-ScsiLun -luntype disk | select VMhost, runtimename, ConsoleDeviceName, MultipathPolicy, CapacityGB, Model | sort ConsoleDeviceName | ft

List Networks
Get-Datacenter $global:DCChoice | Get-Cluster $global:CLUChoice | get-vmhost| get-virtualportgroup | Select Name, Key, VLanID | ft

Check Syslog Config
Get-Datacenter $global:DCChoice | Get-Cluster $global:CLUChoice | get-vmhost | Select Name, @{N="SyslogServer";E={$_ | get-vmhostsyslogserver | Select -ExpandProperty Host}} | ft

Check NTP Config
Get-Datacenter $global:DCChoice | Get-Cluster $global:CLUChoice | get-vmhost | Select Name, @{N="NTPServer";E={$_ | get-vmhostntpserver}} | FT

List specific host VMK adapters
– This creates a function “VP-ListCLUVMK” with a menu so you can select a specific host.

function VP-ListCLUVMK
{
clear
$hostsvmk = Get-datacenter $Global:DCChoice | Get-Cluster $global:CLUChoice | get-vmhost
Write-Host " ================ Get all Hosts in $Global:DCChoice VMkernel Adapters ================" -ForegroundColor green
$i = 1
$hostsvmk | ForEach-Object -Process {
Write-Host " $i $($_.Name)"
$i++
}
$selection = Read-Host " Please make a selection (Q to Quit)"
if($selection -eq 'Q'){
clear
TTRF-Choice-Deploy-Menu
}
else{
$HostChoice = $hostsvmk[$selection -1].Name
Get-Datacenter $global:DCChoice | Get-Cluster $global:CLUChoice | get-vmhost | Get-VMHostNetworkAdapter -VMKernel | select VMhost, DeviceName, Mac, Mtu, DhcpEnabled, IP,SubnetMask, VMotionEnabled, FaultToleranceLoggingEnabled, ManagementTrafficEnabled, VsanTrafficEnabled | Sort VMhost | ft
Write-Host -NoNewLine 'VMK List Exported. Press any key to continue…';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
Get-Datacenter $global:DCChoice | Get-Cluster $global:CLUChoice | get-vmhost | Get-VMHostNetworkAdapter -VMKernel | select VMhost, DeviceName, Mac, Mtu, DhcpEnabled, IP,SubnetMask, VMotionEnabled, FaultToleranceLoggingEnabled, ManagementTrafficEnabled, VsanTrafficEnabled | Sort VMhost | Export-Csv -Path "$Global:FilePath\$global:CLUChoice VMKList $(get-date -f yyyy-MM-dd-hhmm).csv" -NoTypeInformation
clear

}
}

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.