From 307f3d29978c80666797f8a8e3c4a8fa83f7d203 Mon Sep 17 00:00:00 2001 From: William Lam Date: Mon, 23 Jan 2017 08:00:33 -0800 Subject: [PATCH 01/24] First VAMI function Get-VAMISummary --- Modules/VAMI.psm1 | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Modules/VAMI.psm1 diff --git a/Modules/VAMI.psm1 b/Modules/VAMI.psm1 new file mode 100644 index 0000000..abdf4a3 --- /dev/null +++ b/Modules/VAMI.psm1 @@ -0,0 +1,36 @@ +Function Get-VAMISummary { +<# + .NOTES + =========================================================================== + Created by: William Lam + Date: Jan 20, 2016 + Organization: VMware + Blog: www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + .SYNOPSIS + This function retrieves some basic information from VAMI interface (5480) + for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. + .DESCRIPTION + Function to return basic VAMI summary info + .EXAMPLE + Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! + Get-VAMISummary +#> + $systemVersionAPI = Get-CisService -Name 'com.vmware.appliance.system.version' + $results = $systemVersionAPI.get() | select product, type, version, build, install_time + + $systemUptimeAPI = Get-CisService -Name 'com.vmware.appliance.system.uptime' + $ts = [timespan]::fromseconds($systemUptimeAPI.get().toString()) + $uptime = $ts.ToString("hh\:mm\:ss\,fff") + + $summaryResult = "" | Select Product, Type, Version, Build, InstallTime, Uptime + $summaryResult.Product = $results.product + $summaryResult.Type = $results.type + $summaryResult.Version = $results.version + $summaryResult.Build = $results.build + $summaryResult.InstallTime = $results.install_time + $summaryResult.Uptime = $uptime + + $summaryResult +} \ No newline at end of file From e8298afe3a8047a7673cc37804ac81623c0d79cd Mon Sep 17 00:00:00 2001 From: William Lam Date: Wed, 25 Jan 2017 05:54:32 -0800 Subject: [PATCH 02/24] Adding Get-VAMIHealth function --- Modules/VAMI.psm1 | 57 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/Modules/VAMI.psm1 b/Modules/VAMI.psm1 index abdf4a3..6c8c835 100644 --- a/Modules/VAMI.psm1 +++ b/Modules/VAMI.psm1 @@ -2,15 +2,15 @@ <# .NOTES =========================================================================== - Created by: William Lam + Created by: William Lam Date: Jan 20, 2016 - Organization: VMware + Organization: VMware Blog: www.virtuallyghetto.com Twitter: @lamw =========================================================================== .SYNOPSIS This function retrieves some basic information from VAMI interface (5480) - for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. + for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. .DESCRIPTION Function to return basic VAMI summary info .EXAMPLE @@ -33,4 +33,53 @@ $summaryResult.Uptime = $uptime $summaryResult -} \ No newline at end of file +} + +Function Get-VAMIHealth { +<# + .NOTES + =========================================================================== + Created by: William Lam + Date: Jan 20, 2016 + Organization: VMware + Blog: www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + .SYNOPSIS + This function retrieves health information from VAMI interface (5480) + for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. + .DESCRIPTION + Function to return VAMI health + .EXAMPLE + Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! + Get-VAMIHealth +#> + $healthOverall = (Get-CisService -Name 'com.vmware.appliance.health.system').get() + $healthLastCheck = (Get-CisService -Name 'com.vmware.appliance.health.system').lastcheck() + $healthCPU = (Get-CisService -Name 'com.vmware.appliance.health.load').get() + $healthMem = (Get-CisService -Name 'com.vmware.appliance.health.mem').get() + $healthSwap = (Get-CisService -Name 'com.vmware.appliance.health.swap').get() + $healthStorage = (Get-CisService -Name 'com.vmware.appliance.health.storage').get() + + # DB health only applicable for Embedded/External VCSA Node + $vami = (Get-CisService -Name 'com.vmware.appliance.system.version').get() + + if($vami.type -eq "vCenter Server with an embedded Platform Services Controller" -or $vami.type -eq "vCenter Server with an external Platform Services Controller") { + $healthVCDB = (Get-CisService -Name 'com.vmware.appliance.health.databasestorage').get() + } else { + $healthVCDB = "N/A" + } + $healthSoftwareUpdates = (Get-CisService -Name 'com.vmware.appliance.health.softwarepackages').get() + + $healthResult = "" | Select HealthOverall, HealthLastCheck, HealthCPU, HealthMem, HealthSwap, HealthStorage, HealthVCDB, HealthSoftware + $healthResult.HealthOverall = $healthOverall + $healthResult.HealthLastCheck = $healthLastCheck + $healthResult.HealthCPU = $healthCPU + $healthResult.HealthMem = $healthMem + $healthResult.HealthSwap = $healthSwap + $healthResult.HealthStorage = $healthStorage + $healthResult.HealthVCDB = $healthVCDB + $healthResult.HealthSoftware = $healthSoftwareUpdates + + $healthResult +} From 358337db74693a1c9d7ea4c668482b6af8325c44 Mon Sep 17 00:00:00 2001 From: William Lam Date: Thu, 26 Jan 2017 06:25:56 -0800 Subject: [PATCH 03/24] Adding Get-VAMIAccess function --- Modules/VAMI.psm1 | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) mode change 100644 => 100755 Modules/VAMI.psm1 diff --git a/Modules/VAMI.psm1 b/Modules/VAMI.psm1 old mode 100644 new mode 100755 index 6c8c835..3272e6d --- a/Modules/VAMI.psm1 +++ b/Modules/VAMI.psm1 @@ -83,3 +83,36 @@ Function Get-VAMIHealth { $healthResult } + +Function Get-VAMIAccess { +<# + .NOTES + =========================================================================== + Created by: William Lam + Date: Jan 25, 2016 + Organization: VMware + Blog: www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + .SYNOPSIS + This function retrieves access information from VAMI interface (5480) + for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. + .DESCRIPTION + Function to return VAMI access interfaces (Console,DCUI,Bash Shell & SSH) + .EXAMPLE + Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! + Get-VAMIAccess +#> + $consoleAccess = (Get-CisService -Name 'com.vmware.appliance.access.consolecli').get() + $dcuiAccess = (Get-CisService -Name 'com.vmware.appliance.access.dcui').get() + $shellAccess = (Get-CisService -Name 'com.vmware.appliance.access.shell').get() + $sshAccess = (Get-CisService -Name 'com.vmware.appliance.access.ssh').get() + + $accessResult = "" | Select Console, DCUI, BashShell, SSH + $accessResult.Console = $consoleAccess + $accessResult.DCUI = $dcuiAccess + $accessResult.BashShell = $shellAccess.enabled + $accessResult.SSH = $sshAccess + + $accessResult +} \ No newline at end of file From c5de6447f6c9ceb7847cc837252bc63b9baf6191 Mon Sep 17 00:00:00 2001 From: William Lam Date: Fri, 27 Jan 2017 09:48:52 -0800 Subject: [PATCH 04/24] Adding Get-VAMITime function --- Modules/VAMI.psm1 | 48 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/Modules/VAMI.psm1 b/Modules/VAMI.psm1 index 3272e6d..37e54f3 100755 --- a/Modules/VAMI.psm1 +++ b/Modules/VAMI.psm1 @@ -88,9 +88,9 @@ Function Get-VAMIAccess { <# .NOTES =========================================================================== - Created by: William Lam + Created by: William Lam Date: Jan 25, 2016 - Organization: VMware + Organization: VMware Blog: www.virtuallyghetto.com Twitter: @lamw =========================================================================== @@ -115,4 +115,48 @@ Function Get-VAMIAccess { $accessResult.SSH = $sshAccess $accessResult +} + +Function Get-VAMITime { +<# + .NOTES + =========================================================================== + Created by: William Lam + Date: Jan 27, 2016 + Organization: VMware + Blog: www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + .SYNOPSIS + This function retrieves the time and NTP info from VAMI interface (5480) + for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. + .DESCRIPTION + Function to return current Time and NTP information + .EXAMPLE + Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! + Get-VAMITime +#> + $systemTimeAPI = Get-CisService -Name 'com.vmware.appliance.system.time' + $timeResults = $systemTimeAPI.get() + + $timeResult = "" | Select Timezone, Date, CurrentTime, Mode, NTPServers, NTPStatus + $timeResult.Timezone = $timeResults.timezone + $timeResult.Date = $timeResults.date + $timeResult.CurrentTime = $timeResults.time + + $timeSync = (Get-CisService -Name 'com.vmware.appliance.techpreview.timesync').get() + $timeSyncMode = $timeSync.mode + + $timeResult.Mode = $timeSyncMode + + if($timeSyncMode -eq "NTP") { + $ntpServers = (Get-CisService -Name 'com.vmware.appliance.techpreview.ntp').get() + $timeResult.NTPServers = $ntpServers.servers + $timeResult.NTPStatus = $ntpServers.status + } else { + $timeResult.NTPServers = "N/A" + $timeResult.NTPStatus = "N/A" + } + + $timeResult } \ No newline at end of file From 860b62df5b69fd45144c9220f89eacd1d224a587 Mon Sep 17 00:00:00 2001 From: William Lam Date: Fri, 27 Jan 2017 09:50:49 -0800 Subject: [PATCH 05/24] Fixing spaces --- Modules/VAMI.psm1 | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Modules/VAMI.psm1 b/Modules/VAMI.psm1 index 37e54f3..515b274 100755 --- a/Modules/VAMI.psm1 +++ b/Modules/VAMI.psm1 @@ -2,9 +2,9 @@ <# .NOTES =========================================================================== - Created by: William Lam + Created by: William Lam Date: Jan 20, 2016 - Organization: VMware + Organization: VMware Blog: www.virtuallyghetto.com Twitter: @lamw =========================================================================== @@ -39,9 +39,9 @@ Function Get-VAMIHealth { <# .NOTES =========================================================================== - Created by: William Lam - Date: Jan 20, 2016 - Organization: VMware + Created by: William Lam + Date: Jan 25, 2016 + Organization: VMware Blog: www.virtuallyghetto.com Twitter: @lamw =========================================================================== @@ -88,9 +88,9 @@ Function Get-VAMIAccess { <# .NOTES =========================================================================== - Created by: William Lam - Date: Jan 25, 2016 - Organization: VMware + Created by: William Lam + Date: Jan 26, 2016 + Organization: VMware Blog: www.virtuallyghetto.com Twitter: @lamw =========================================================================== @@ -121,9 +121,9 @@ Function Get-VAMITime { <# .NOTES =========================================================================== - Created by: William Lam + Created by: William Lam Date: Jan 27, 2016 - Organization: VMware + Organization: VMware Blog: www.virtuallyghetto.com Twitter: @lamw =========================================================================== From f595e7e67411c87f45f1d43528c65f48bcc2d33f Mon Sep 17 00:00:00 2001 From: William Lam Date: Tue, 31 Jan 2017 15:13:56 -0800 Subject: [PATCH 06/24] Adding Get-VAMINetwork function --- Modules/VAMI.psm1 | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/Modules/VAMI.psm1 b/Modules/VAMI.psm1 index 515b274..16abc76 100755 --- a/Modules/VAMI.psm1 +++ b/Modules/VAMI.psm1 @@ -159,4 +159,54 @@ Function Get-VAMITime { } $timeResult +} + +Function Get-VAMINetwork { +<# + .NOTES + =========================================================================== + Created by: William Lam + Date: Jan 31, 2016 + Organization: VMware + Blog: www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + .SYNOPSIS + This function retrieves access information from VAMI interface (5480) + for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. + .DESCRIPTION + Function to return VAMI access interfaces (Console,DCUI,Bash Shell & SSH) + .EXAMPLE + Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! + Get-VAMINetwork +#> + $netResults = @() + + $Hostname = (Get-CisService -Name 'com.vmware.appliance.networking.dns.hostname').get() + $dns = (Get-CisService -Name 'com.vmware.appliance.networking.dns.servers').get() + + Write-Host "Hostname: " $hostname + Write-Host "DNS Servers: " $dns.servers + + $interfaces = (Get-CisService -Name 'com.vmware.appliance.networking.interfaces').list() + foreach ($interface in $interfaces) { + $interfaceResult = "" | Select Inteface, MAC, Status, Mode, IP, Prefix, Gateway, Updateable + + $interfaceResult.Inteface = $interface.name + $interfaceResult.MAC = $interface.mac + $interfaceResult.Status = $interface.status + + $ipv4API = (Get-CisService -Name 'com.vmware.appliance.techpreview.networking.ipv4') + $spec = $ipv4API.Help.get.interfaces.CreateExample() + $spec+= $interface.name + $ipv4result = $ipv4API.get($spec) + + $interfaceResult.Mode = $ipv4result.mode + $interfaceResult.IP = $ipv4result.address + $interfaceResult.Prefix = $ipv4result.prefix + $interfaceResult.Gateway = $ipv4result.default_gateway + $interfaceResult.Updateable = $ipv4result.updateable + $netResults += $interfaceResult + } + $netResults } \ No newline at end of file From dd9723cf7b76934be10c5d5e312b51c4f6ec410e Mon Sep 17 00:00:00 2001 From: William Lam Date: Wed, 1 Feb 2017 08:24:05 -0800 Subject: [PATCH 07/24] Fixing comments --- Modules/VAMI.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/VAMI.psm1 b/Modules/VAMI.psm1 index 16abc76..8a1dc05 100755 --- a/Modules/VAMI.psm1 +++ b/Modules/VAMI.psm1 @@ -172,10 +172,10 @@ Function Get-VAMINetwork { Twitter: @lamw =========================================================================== .SYNOPSIS - This function retrieves access information from VAMI interface (5480) + This function retrieves network information from VAMI interface (5480) for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. .DESCRIPTION - Function to return VAMI access interfaces (Console,DCUI,Bash Shell & SSH) + Function to return networking information including details for each interface .EXAMPLE Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! Get-VAMINetwork From 2d6d3205e11b3d2d1b15a072c1ca5ba8b271eab8 Mon Sep 17 00:00:00 2001 From: William Lam Date: Tue, 31 Jan 2017 15:13:56 -0800 Subject: [PATCH 08/24] Adding Get-VAMINetwork function Fixing comments --- Modules/VAMI.psm1 | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/Modules/VAMI.psm1 b/Modules/VAMI.psm1 index 515b274..8a1dc05 100755 --- a/Modules/VAMI.psm1 +++ b/Modules/VAMI.psm1 @@ -159,4 +159,54 @@ Function Get-VAMITime { } $timeResult +} + +Function Get-VAMINetwork { +<# + .NOTES + =========================================================================== + Created by: William Lam + Date: Jan 31, 2016 + Organization: VMware + Blog: www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + .SYNOPSIS + This function retrieves network information from VAMI interface (5480) + for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. + .DESCRIPTION + Function to return networking information including details for each interface + .EXAMPLE + Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! + Get-VAMINetwork +#> + $netResults = @() + + $Hostname = (Get-CisService -Name 'com.vmware.appliance.networking.dns.hostname').get() + $dns = (Get-CisService -Name 'com.vmware.appliance.networking.dns.servers').get() + + Write-Host "Hostname: " $hostname + Write-Host "DNS Servers: " $dns.servers + + $interfaces = (Get-CisService -Name 'com.vmware.appliance.networking.interfaces').list() + foreach ($interface in $interfaces) { + $interfaceResult = "" | Select Inteface, MAC, Status, Mode, IP, Prefix, Gateway, Updateable + + $interfaceResult.Inteface = $interface.name + $interfaceResult.MAC = $interface.mac + $interfaceResult.Status = $interface.status + + $ipv4API = (Get-CisService -Name 'com.vmware.appliance.techpreview.networking.ipv4') + $spec = $ipv4API.Help.get.interfaces.CreateExample() + $spec+= $interface.name + $ipv4result = $ipv4API.get($spec) + + $interfaceResult.Mode = $ipv4result.mode + $interfaceResult.IP = $ipv4result.address + $interfaceResult.Prefix = $ipv4result.prefix + $interfaceResult.Gateway = $ipv4result.default_gateway + $interfaceResult.Updateable = $ipv4result.updateable + $netResults += $interfaceResult + } + $netResults } \ No newline at end of file From e3c9108ae8752c13912d5d2ce5142f67345e0426 Mon Sep 17 00:00:00 2001 From: William Lam Date: Wed, 1 Feb 2017 08:56:02 -0800 Subject: [PATCH 09/24] Using splat method for creating PS Objects --- Modules/VAMI.psm1 | 83 ++++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/Modules/VAMI.psm1 b/Modules/VAMI.psm1 index 8a1dc05..e3aaab4 100755 --- a/Modules/VAMI.psm1 +++ b/Modules/VAMI.psm1 @@ -24,13 +24,14 @@ $ts = [timespan]::fromseconds($systemUptimeAPI.get().toString()) $uptime = $ts.ToString("hh\:mm\:ss\,fff") - $summaryResult = "" | Select Product, Type, Version, Build, InstallTime, Uptime - $summaryResult.Product = $results.product - $summaryResult.Type = $results.type - $summaryResult.Version = $results.version - $summaryResult.Build = $results.build - $summaryResult.InstallTime = $results.install_time - $summaryResult.Uptime = $uptime + $summaryResult = New-Object PSObject -Property @{ + Product = $results.product; + Type = $results.type; + Version = $results.version; + Build = $results.build; + InstallTime = $results.install_time; + Uptime = $uptime + } $summaryResult } @@ -71,15 +72,16 @@ Function Get-VAMIHealth { } $healthSoftwareUpdates = (Get-CisService -Name 'com.vmware.appliance.health.softwarepackages').get() - $healthResult = "" | Select HealthOverall, HealthLastCheck, HealthCPU, HealthMem, HealthSwap, HealthStorage, HealthVCDB, HealthSoftware - $healthResult.HealthOverall = $healthOverall - $healthResult.HealthLastCheck = $healthLastCheck - $healthResult.HealthCPU = $healthCPU - $healthResult.HealthMem = $healthMem - $healthResult.HealthSwap = $healthSwap - $healthResult.HealthStorage = $healthStorage - $healthResult.HealthVCDB = $healthVCDB - $healthResult.HealthSoftware = $healthSoftwareUpdates + $healthResult = New-Object PSObject -Property @{ + HealthOverall = $healthOverall; + HealthLastCheck = $healthLastCheck; + HealthCPU = $healthCPU; + HealthMem = $healthMem; + HealthSwap = $healthSwap; + HealthStorage = $healthStorage; + HealthVCDB = $healthVCDB; + HealthSoftware = $healthSoftwareUpdates + } $healthResult } @@ -108,11 +110,12 @@ Function Get-VAMIAccess { $shellAccess = (Get-CisService -Name 'com.vmware.appliance.access.shell').get() $sshAccess = (Get-CisService -Name 'com.vmware.appliance.access.ssh').get() - $accessResult = "" | Select Console, DCUI, BashShell, SSH - $accessResult.Console = $consoleAccess - $accessResult.DCUI = $dcuiAccess - $accessResult.BashShell = $shellAccess.enabled - $accessResult.SSH = $sshAccess + $accessResult = New-Object PSObject -Property @{ + Console = $consoleAccess; + DCUI = $dcuiAccess; + BashShell = $shellAccess.enabled; + SSH = $sshAccess + } $accessResult } @@ -139,23 +142,22 @@ Function Get-VAMITime { $systemTimeAPI = Get-CisService -Name 'com.vmware.appliance.system.time' $timeResults = $systemTimeAPI.get() - $timeResult = "" | Select Timezone, Date, CurrentTime, Mode, NTPServers, NTPStatus - $timeResult.Timezone = $timeResults.timezone - $timeResult.Date = $timeResults.date - $timeResult.CurrentTime = $timeResults.time - $timeSync = (Get-CisService -Name 'com.vmware.appliance.techpreview.timesync').get() $timeSyncMode = $timeSync.mode - $timeResult.Mode = $timeSyncMode + $timeResult = New-Object PSObject -Property @{ + Timezone = $timeResults.timezone; + Date = $timeResults.date; + CurrentTime = $timeResults.time; + Mode = $timeSyncMode; + NTPServers = "N/A"; + NTPStatus = "N/A"; + } if($timeSyncMode -eq "NTP") { $ntpServers = (Get-CisService -Name 'com.vmware.appliance.techpreview.ntp').get() $timeResult.NTPServers = $ntpServers.servers $timeResult.NTPStatus = $ntpServers.status - } else { - $timeResult.NTPServers = "N/A" - $timeResult.NTPStatus = "N/A" } $timeResult @@ -190,22 +192,21 @@ Function Get-VAMINetwork { $interfaces = (Get-CisService -Name 'com.vmware.appliance.networking.interfaces').list() foreach ($interface in $interfaces) { - $interfaceResult = "" | Select Inteface, MAC, Status, Mode, IP, Prefix, Gateway, Updateable - - $interfaceResult.Inteface = $interface.name - $interfaceResult.MAC = $interface.mac - $interfaceResult.Status = $interface.status - $ipv4API = (Get-CisService -Name 'com.vmware.appliance.techpreview.networking.ipv4') $spec = $ipv4API.Help.get.interfaces.CreateExample() $spec+= $interface.name $ipv4result = $ipv4API.get($spec) - $interfaceResult.Mode = $ipv4result.mode - $interfaceResult.IP = $ipv4result.address - $interfaceResult.Prefix = $ipv4result.prefix - $interfaceResult.Gateway = $ipv4result.default_gateway - $interfaceResult.Updateable = $ipv4result.updateable + $interfaceResult = New-Object PSObject -Property @{ + Inteface = $interface.name; + MAC = $interface.mac; + Status = $interface.status; + Mode = $ipv4result.mode; + IP = $ipv4result.address; + Prefix = $ipv4result.prefix; + Gateway = $ipv4result.default_gateway; + Updateable = $ipv4result.updateable + } $netResults += $interfaceResult } $netResults From 0d1c8c79c8ec776b86cd726718eb33833b402e7c Mon Sep 17 00:00:00 2001 From: William Lam Date: Wed, 1 Feb 2017 09:45:32 -0800 Subject: [PATCH 10/24] Fixing spacing --- Modules/VAMI.psm1 | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/Modules/VAMI.psm1 b/Modules/VAMI.psm1 index e3aaab4..cf50563 100755 --- a/Modules/VAMI.psm1 +++ b/Modules/VAMI.psm1 @@ -8,12 +8,12 @@ Blog: www.virtuallyghetto.com Twitter: @lamw =========================================================================== - .SYNOPSIS - This function retrieves some basic information from VAMI interface (5480) + .SYNOPSIS + This function retrieves some basic information from VAMI interface (5480) for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. - .DESCRIPTION - Function to return basic VAMI summary info - .EXAMPLE + .DESCRIPTION + Function to return basic VAMI summary info + .EXAMPLE Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! Get-VAMISummary #> @@ -32,7 +32,6 @@ InstallTime = $results.install_time; Uptime = $uptime } - $summaryResult } @@ -46,12 +45,12 @@ Function Get-VAMIHealth { Blog: www.virtuallyghetto.com Twitter: @lamw =========================================================================== - .SYNOPSIS + .SYNOPSIS This function retrieves health information from VAMI interface (5480) for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. - .DESCRIPTION + .DESCRIPTION Function to return VAMI health - .EXAMPLE + .EXAMPLE Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! Get-VAMIHealth #> @@ -82,7 +81,6 @@ Function Get-VAMIHealth { HealthVCDB = $healthVCDB; HealthSoftware = $healthSoftwareUpdates } - $healthResult } @@ -96,12 +94,12 @@ Function Get-VAMIAccess { Blog: www.virtuallyghetto.com Twitter: @lamw =========================================================================== - .SYNOPSIS + .SYNOPSIS This function retrieves access information from VAMI interface (5480) for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. - .DESCRIPTION + .DESCRIPTION Function to return VAMI access interfaces (Console,DCUI,Bash Shell & SSH) - .EXAMPLE + .EXAMPLE Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! Get-VAMIAccess #> @@ -116,7 +114,6 @@ Function Get-VAMIAccess { BashShell = $shellAccess.enabled; SSH = $sshAccess } - $accessResult } @@ -130,12 +127,12 @@ Function Get-VAMITime { Blog: www.virtuallyghetto.com Twitter: @lamw =========================================================================== - .SYNOPSIS + .SYNOPSIS This function retrieves the time and NTP info from VAMI interface (5480) for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. - .DESCRIPTION + .DESCRIPTION Function to return current Time and NTP information - .EXAMPLE + .EXAMPLE Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! Get-VAMITime #> @@ -159,7 +156,6 @@ Function Get-VAMITime { $timeResult.NTPServers = $ntpServers.servers $timeResult.NTPStatus = $ntpServers.status } - $timeResult } @@ -173,12 +169,12 @@ Function Get-VAMINetwork { Blog: www.virtuallyghetto.com Twitter: @lamw =========================================================================== - .SYNOPSIS + .SYNOPSIS This function retrieves network information from VAMI interface (5480) for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. - .DESCRIPTION + .DESCRIPTION Function to return networking information including details for each interface - .EXAMPLE + .EXAMPLE Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! Get-VAMINetwork #> From e210b2f229fb2df519f79b70b4575ca2c987c88b Mon Sep 17 00:00:00 2001 From: William Lam Date: Wed, 1 Feb 2017 09:46:57 -0800 Subject: [PATCH 11/24] More spacing fixes --- Modules/VAMI.psm1 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Modules/VAMI.psm1 b/Modules/VAMI.psm1 index cf50563..cc8e92e 100755 --- a/Modules/VAMI.psm1 +++ b/Modules/VAMI.psm1 @@ -46,10 +46,10 @@ Function Get-VAMIHealth { Twitter: @lamw =========================================================================== .SYNOPSIS - This function retrieves health information from VAMI interface (5480) + This function retrieves health information from VAMI interface (5480) for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. .DESCRIPTION - Function to return VAMI health + Function to return VAMI health .EXAMPLE Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! Get-VAMIHealth @@ -95,10 +95,10 @@ Function Get-VAMIAccess { Twitter: @lamw =========================================================================== .SYNOPSIS - This function retrieves access information from VAMI interface (5480) + This function retrieves access information from VAMI interface (5480) for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. .DESCRIPTION - Function to return VAMI access interfaces (Console,DCUI,Bash Shell & SSH) + Function to return VAMI access interfaces (Console,DCUI,Bash Shell & SSH) .EXAMPLE Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! Get-VAMIAccess @@ -128,10 +128,10 @@ Function Get-VAMITime { Twitter: @lamw =========================================================================== .SYNOPSIS - This function retrieves the time and NTP info from VAMI interface (5480) + This function retrieves the time and NTP info from VAMI interface (5480) for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. .DESCRIPTION - Function to return current Time and NTP information + Function to return current Time and NTP information .EXAMPLE Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! Get-VAMITime @@ -170,10 +170,10 @@ Function Get-VAMINetwork { Twitter: @lamw =========================================================================== .SYNOPSIS - This function retrieves network information from VAMI interface (5480) + This function retrieves network information from VAMI interface (5480) for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. .DESCRIPTION - Function to return networking information including details for each interface + Function to return networking information including details for each interface .EXAMPLE Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! Get-VAMINetwork From 38baff0d311865409b6d1af67d0afbdab9997b52 Mon Sep 17 00:00:00 2001 From: William Lam Date: Wed, 1 Feb 2017 12:21:09 -0800 Subject: [PATCH 12/24] Using pscustomobject to keep ordering --- Modules/VAMI.psm1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Modules/VAMI.psm1 b/Modules/VAMI.psm1 index cc8e92e..6b80497 100755 --- a/Modules/VAMI.psm1 +++ b/Modules/VAMI.psm1 @@ -24,7 +24,7 @@ $ts = [timespan]::fromseconds($systemUptimeAPI.get().toString()) $uptime = $ts.ToString("hh\:mm\:ss\,fff") - $summaryResult = New-Object PSObject -Property @{ + $summaryResult = [pscustomobject] @{ Product = $results.product; Type = $results.type; Version = $results.version; @@ -71,7 +71,7 @@ Function Get-VAMIHealth { } $healthSoftwareUpdates = (Get-CisService -Name 'com.vmware.appliance.health.softwarepackages').get() - $healthResult = New-Object PSObject -Property @{ + $healthResult = [pscustomobject] @{ HealthOverall = $healthOverall; HealthLastCheck = $healthLastCheck; HealthCPU = $healthCPU; @@ -142,7 +142,7 @@ Function Get-VAMITime { $timeSync = (Get-CisService -Name 'com.vmware.appliance.techpreview.timesync').get() $timeSyncMode = $timeSync.mode - $timeResult = New-Object PSObject -Property @{ + $timeResult = [pscustomobject] @{ Timezone = $timeResults.timezone; Date = $timeResults.date; CurrentTime = $timeResults.time; @@ -193,7 +193,7 @@ Function Get-VAMINetwork { $spec+= $interface.name $ipv4result = $ipv4API.get($spec) - $interfaceResult = New-Object PSObject -Property @{ + $interfaceResult = [pscustomobject] @{ Inteface = $interface.name; MAC = $interface.mac; Status = $interface.status; From d4afcd2ab45e7525dbf772fa4b62a177fca358c3 Mon Sep 17 00:00:00 2001 From: William Lam Date: Wed, 1 Feb 2017 19:33:35 -0800 Subject: [PATCH 13/24] Adding Get-VAMIDisks & Start-VAMIDisksResize func --- Modules/VAMI.psm1 | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/Modules/VAMI.psm1 b/Modules/VAMI.psm1 index 6b80497..f1c0635 100755 --- a/Modules/VAMI.psm1 +++ b/Modules/VAMI.psm1 @@ -206,4 +206,55 @@ Function Get-VAMINetwork { $netResults += $interfaceResult } $netResults +} + +Function Get-VAMIDisks { +<# + .NOTES + =========================================================================== + Created by: William Lam + Date: Feb 02, 2016 + Organization: VMware + Blog: www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + .SYNOPSIS + This function retrieves VMDK disk number to partition mapping VAMI interface (5480) + for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. + .DESCRIPTION + Function to return VMDK disk number to OS partition mapping + .EXAMPLE + Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! + Get-VAMIDisks +#> + $storageAPI = Get-CisService -Name 'com.vmware.appliance.system.storage' + $disks = $storageAPI.list() + + foreach ($disk in $disks | sort {[int]$_.disk.toString()}) { + $disk | Select Disk, Partition + } +} + +Function Start-VAMIDiskResize { +<# + .NOTES + =========================================================================== + Created by: William Lam + Date: Feb 02, 2016 + Organization: VMware + Blog: www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + .SYNOPSIS + This function triggers an OS partition resize after adding additional disk capacity + for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. + .DESCRIPTION + Function triggers OS partition resize operation + .EXAMPLE + Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! + Start-VAMIDiskResize +#> + $storageAPI = Get-CisService -Name 'com.vmware.appliance.system.storage' + Write-Host "Initiated OS partition resize operation ..." + $storageAPI.resize() } \ No newline at end of file From 0e037f19a441dc8bbb9ed45100c7af09d9436783 Mon Sep 17 00:00:00 2001 From: William Lam Date: Mon, 6 Feb 2017 12:37:01 -0800 Subject: [PATCH 14/24] Adding Get-VAMIStatsList & Get-VAMIStorageUsed functions --- Modules/VAMI.psm1 | 125 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) diff --git a/Modules/VAMI.psm1 b/Modules/VAMI.psm1 index f1c0635..62887d9 100755 --- a/Modules/VAMI.psm1 +++ b/Modules/VAMI.psm1 @@ -257,4 +257,129 @@ Function Start-VAMIDiskResize { $storageAPI = Get-CisService -Name 'com.vmware.appliance.system.storage' Write-Host "Initiated OS partition resize operation ..." $storageAPI.resize() +} + +Function Get-VAMIStatsList { +<# + .NOTES + =========================================================================== + Created by: William Lam + Date: Feb 06, 2016 + Organization: VMware + Blog: www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + .SYNOPSIS + This function retrieves list avialable monitoring metrics in VAMI interface (5480) + for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. + .DESCRIPTION + Function to return list of available monitoring metrics that can be queried + .EXAMPLE + Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! + Get-VAMIStatsList +#> + $monitoringAPI = Get-CisService -Name 'com.vmware.appliance.monitoring' + $ids = $monitoringAPI.list() | Select id | Sort-Object -Property id + + foreach ($id in $ids) { + $id + } +} + +Function Get-VAMIStorageUsed { +<# + .NOTES + =========================================================================== + Created by: William Lam + Date: Feb 06, 2016 + Organization: VMware + Blog: www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + .SYNOPSIS + This function retrieves the individaul OS partition storage utilization + for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. + .DESCRIPTION + Function to return individual OS partition storage utilization + .EXAMPLE + Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! + Get-VAMIStorageUsed +#> + $monitoringAPI = Get-CisService 'com.vmware.appliance.monitoring' + $querySpec = $monitoringAPI.help.query.item.CreateExample() + + # List of IDs from Get-VAMIStatsList to query + $querySpec.Names = @( + "storage.used.filesystem.autodeploy", + "storage.used.filesystem.boot", + "storage.used.filesystem.coredump", + "storage.used.filesystem.imagebuilder", + "storage.used.filesystem.invsvc", + "storage.used.filesystem.log", + "storage.used.filesystem.netdump", + "storage.used.filesystem.root", + "storage.used.filesystem.updatemgr", + "storage.used.filesystem.vcdb_core_inventory", + "storage.used.filesystem.vcdb_seat", + "storage.used.filesystem.vcdb_transaction_log", + "storage.totalsize.filesystem.autodeploy", + "storage.totalsize.filesystem.boot", + "storage.totalsize.filesystem.coredump", + "storage.totalsize.filesystem.imagebuilder", + "storage.totalsize.filesystem.invsvc", + "storage.totalsize.filesystem.log", + "storage.totalsize.filesystem.netdump", + "storage.totalsize.filesystem.root", + "storage.totalsize.filesystem.updatemgr", + "storage.totalsize.filesystem.vcdb_core_inventory", + "storage.totalsize.filesystem.vcdb_seat", + "storage.totalsize.filesystem.vcdb_transaction_log" + ) + + # Tuple (Filesystem Name, Used, Total) to store results + $storageStats = @{ + "autodeploy"=@{"name"="/storage/autodeploy";"used"=0;"total"=0}; + "boot"=@{"name"="/boot";"used"=0;"total"=0}; + "coredump"=@{"name"="/storage/core";"used"=0;"total"=0}; + "imagebuilder"=@{"name"="/storage/imagebuilder";"used"=0;"total"=0}; + "invsvc"=@{"name"="/storage/invsvc";"used"=0;"total"=0}; + "log"=@{"name"="/storage/log";"used"=0;"total"=0}; + "netdump"=@{"name"="/storage/netdump";"used"=0;"total"=0}; + "root"=@{"name"="/";"used"=0;"total"=0}; + "updatemgr"=@{"name"="/storage/updatemgr";"used"=0;"total"=0}; + "vcdb_core_inventory"=@{"name"="/storage/db";"used"=0;"total"=0}; + "vcdb_seat"=@{"name"="/storage/seat";"used"=0;"total"=0}; + "vcdb_transaction_log"=@{"name"="/storage/dblog";"used"=0;"total"=0} + } + + $querySpec.interval = "DAY1" + $querySpec.function = "MAX" + $querySpec.start_time = ((get-date).AddDays(-1)) + $querySpec.end_time = (Get-Date) + $queryResults = $monitoringAPI.query($querySpec) | Select * -ExcludeProperty Help + + foreach ($queryResult in $queryResults) { + # Update hash if its used storage results + if($queryResult.name -match "used") { + $key = (($queryResult.name).toString()).split(".")[-1] + $value = [Math]::Round([int]($queryResult.data[1]).toString()/1MB,2) + $storageStats[$key]["used"] = $value + # Update hash if its total storage results + } else { + $key = (($queryResult.name).toString()).split(".")[-1] + $value = [Math]::Round([int]($queryResult.data[1]).toString()/1MB,2) + $storageStats[$key]["total"] = $value + } + } + + $storageResults = @() + foreach ($key in $storageStats.keys | Sort-Object -Property name) { + $statResult = [pscustomobject] @{ + Filesystem = $storageStats[$key].name; + Used = $storageStats[$key].used; + Total = $storageStats[$key].total + } + $storageResults += $statResult + } + $storageResults } \ No newline at end of file From 1fc4b3786353fdc997560ad5f7431610a6a5888a Mon Sep 17 00:00:00 2001 From: William Lam Date: Tue, 7 Feb 2017 12:42:06 -0800 Subject: [PATCH 15/24] Adding {Get,Start,Stop}-VAMIService function --- Modules/VAMI.psm1 | 142 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) diff --git a/Modules/VAMI.psm1 b/Modules/VAMI.psm1 index 62887d9..a66d3c1 100755 --- a/Modules/VAMI.psm1 +++ b/Modules/VAMI.psm1 @@ -382,4 +382,146 @@ Function Get-VAMIStorageUsed { $storageResults += $statResult } $storageResults +} + +Function Get-VAMIService { +<# + .NOTES + =========================================================================== + Created by: William Lam + Date: Feb 08, 2016 + Organization: VMware + Blog: www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + .SYNOPSIS + This function retrieves list of services in VAMI interface (5480) + for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. + .DESCRIPTION + Function to return list of services and their description + .EXAMPLE + Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! + Get-VAMIService + .EXAMPLE + Get-VAMIService -Name rbd +#> + param( + [Parameter( + Mandatory=$false, + ValueFromPipeline=$true, + ValueFromPipelineByPropertyName=$true) + ] + [String]$Name + ) + + if($Name -ne "") { + $vMonAPI = Get-CisService 'com.vmware.appliance.vmon.service' + + try { + $serviceStatus = $vMonAPI.get($name,0) + $serviceString = [pscustomobject] @{ + Name = $name; + State = $serviceStatus.state; + Health = ""; + Startup = $serviceStatus.startup_type + } + if($serviceStatus.health -eq $null) { $serviceString.Health = "N/A"} else { $serviceString.Health = $serviceStatus.health } + $serviceString + } catch { + Write-Error $Error[0].exception.Message + } + } else { + $vMonAPI = Get-CisService 'com.vmware.appliance.vmon.service' + $services = $vMonAPI.list_details() + + $serviceResult = @() + foreach ($key in $services.keys | Sort-Object -Property Value) { + $serviceString = [pscustomobject] @{ + Name = $key; + State = $services[$key].state; + Health = "N/A"; + Startup = $services[$key].Startup_type + } + if($services[$key].health -eq $null) { $serviceString.Health = "N/A"} else { $serviceString.Health = $services[$key].health } + + $serviceResult += $serviceString + } + $serviceResult + } +} + +Function Start-VAMIService { +<# + .NOTES + =========================================================================== + Created by: William Lam + Date: Feb 08, 2016 + Organization: VMware + Blog: www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + .SYNOPSIS + This function retrieves list of services in VAMI interface (5480) + for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. + .DESCRIPTION + Function to return list of services and their description + .EXAMPLE + Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! + Start-VAMIService -Name rbd +#> + param( + [Parameter( + Mandatory=$true, + ValueFromPipeline=$true, + ValueFromPipelineByPropertyName=$true) + ] + [String]$Name + ) + + $vMonAPI = Get-CisService 'com.vmware.appliance.vmon.service' + + try { + Write-Host "Starting $name service ..." + $vMonAPI.start($name) + } catch { + Write-Error $Error[0].exception.Message + } +} + +Function Stop-VAMIService { +<# + .NOTES + =========================================================================== + Created by: William Lam + Date: Feb 08, 2016 + Organization: VMware + Blog: www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + .SYNOPSIS + This function retrieves list of services in VAMI interface (5480) + for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. + .DESCRIPTION + Function to return list of services and their description + .EXAMPLE + Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! + Stop-VAMIService -Name rbd +#> + param( + [Parameter( + Mandatory=$true, + ValueFromPipeline=$true, + ValueFromPipelineByPropertyName=$true) + ] + [String]$Name + ) + + $vMonAPI = Get-CisService 'com.vmware.appliance.vmon.service' + + try { + Write-Host "Stopping $name service ..." + $vMonAPI.stop($name) + } catch { + Write-Error $Error[0].exception.Message + } } \ No newline at end of file From 530764394a87ffa5729810f2a9d4814848a46fc6 Mon Sep 17 00:00:00 2001 From: William Lam Date: Thu, 2 Mar 2017 07:06:53 -0800 Subject: [PATCH 16/24] Adding Get-VAMIBackupSize function --- Modules/VAMI.psm1 | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/Modules/VAMI.psm1 b/Modules/VAMI.psm1 index a66d3c1..6c8038e 100755 --- a/Modules/VAMI.psm1 +++ b/Modules/VAMI.psm1 @@ -3,7 +3,6 @@ .NOTES =========================================================================== Created by: William Lam - Date: Jan 20, 2016 Organization: VMware Blog: www.virtuallyghetto.com Twitter: @lamw @@ -40,7 +39,6 @@ Function Get-VAMIHealth { .NOTES =========================================================================== Created by: William Lam - Date: Jan 25, 2016 Organization: VMware Blog: www.virtuallyghetto.com Twitter: @lamw @@ -89,7 +87,6 @@ Function Get-VAMIAccess { .NOTES =========================================================================== Created by: William Lam - Date: Jan 26, 2016 Organization: VMware Blog: www.virtuallyghetto.com Twitter: @lamw @@ -122,7 +119,6 @@ Function Get-VAMITime { .NOTES =========================================================================== Created by: William Lam - Date: Jan 27, 2016 Organization: VMware Blog: www.virtuallyghetto.com Twitter: @lamw @@ -164,7 +160,6 @@ Function Get-VAMINetwork { .NOTES =========================================================================== Created by: William Lam - Date: Jan 31, 2016 Organization: VMware Blog: www.virtuallyghetto.com Twitter: @lamw @@ -213,7 +208,6 @@ Function Get-VAMIDisks { .NOTES =========================================================================== Created by: William Lam - Date: Feb 02, 2016 Organization: VMware Blog: www.virtuallyghetto.com Twitter: @lamw @@ -240,7 +234,6 @@ Function Start-VAMIDiskResize { .NOTES =========================================================================== Created by: William Lam - Date: Feb 02, 2016 Organization: VMware Blog: www.virtuallyghetto.com Twitter: @lamw @@ -264,7 +257,6 @@ Function Get-VAMIStatsList { .NOTES =========================================================================== Created by: William Lam - Date: Feb 06, 2016 Organization: VMware Blog: www.virtuallyghetto.com Twitter: @lamw @@ -291,7 +283,6 @@ Function Get-VAMIStorageUsed { .NOTES =========================================================================== Created by: William Lam - Date: Feb 06, 2016 Organization: VMware Blog: www.virtuallyghetto.com Twitter: @lamw @@ -389,7 +380,6 @@ Function Get-VAMIService { .NOTES =========================================================================== Created by: William Lam - Date: Feb 08, 2016 Organization: VMware Blog: www.virtuallyghetto.com Twitter: @lamw @@ -455,7 +445,6 @@ Function Start-VAMIService { .NOTES =========================================================================== Created by: William Lam - Date: Feb 08, 2016 Organization: VMware Blog: www.virtuallyghetto.com Twitter: @lamw @@ -493,7 +482,6 @@ Function Stop-VAMIService { .NOTES =========================================================================== Created by: William Lam - Date: Feb 08, 2016 Organization: VMware Blog: www.virtuallyghetto.com Twitter: @lamw @@ -524,4 +512,38 @@ Function Stop-VAMIService { } catch { Write-Error $Error[0].exception.Message } +} + +Function Get-VAMIBackupSize { +<# + .NOTES + =========================================================================== + Created by: William Lam + Organization: VMware + Blog: www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + .SYNOPSIS + This function retrieves the backup size of the VCSA from VAMI interface (5480) + for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. + .DESCRIPTION + Function to return the current backup size of the VCSA (common and core data) + .EXAMPLE + Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! + Get-VAMIBackupSize +#> + $recoveryAPI = Get-CisService 'com.vmware.appliance.recovery.backup.parts' + $backupParts = $recoveryAPI.list() | select id + + $estimateBackupSize = 0 + $backupPartSizes = "" + foreach ($backupPart in $backupParts) { + $partId = $backupPart.id.value + $partSize = $recoveryAPI.get($partId) + $estimateBackupSize += $partSize + $backupPartSizes += $partId + " data is " + $partSize + " MB`n" + } + + Write-Host "Estimated Backup Size: $estimateBackupSize MB" + Write-Host $backupPartSizes } \ No newline at end of file From 0038d751f00223067cd39cddf9cda06a561c5027 Mon Sep 17 00:00:00 2001 From: William Lam Date: Mon, 6 Mar 2017 14:53:16 -0800 Subject: [PATCH 17/24] Adding {New,Get,Remove}-VAMIUser functions --- Modules/VAMI.psm1 | 167 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) diff --git a/Modules/VAMI.psm1 b/Modules/VAMI.psm1 index 6c8038e..92c5d5f 100755 --- a/Modules/VAMI.psm1 +++ b/Modules/VAMI.psm1 @@ -546,4 +546,171 @@ Function Get-VAMIBackupSize { Write-Host "Estimated Backup Size: $estimateBackupSize MB" Write-Host $backupPartSizes +} + +Function Get-VAMIUser { +<# + .NOTES + =========================================================================== + Created by: William Lam + Organization: VMware + Blog: www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + .SYNOPSIS + This function retrieves VAMI local users using VAMI interface (5480) + for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. + .DESCRIPTION + Function to retrieve VAMI local users + .EXAMPLE + Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! + Get-VAMIUser +#> + param( + [Parameter( + Mandatory=$false, + ValueFromPipeline=$true, + ValueFromPipelineByPropertyName=$true) + ] + [String]$Name + ) + + $userAPI = Get-CisService 'com.vmware.appliance.techpreview.localaccounts.user' + + $userResults = @() + + if($Name -ne "") { + try { + $user = $userAPI.get($name) + + $userString = [pscustomobject] @{ + User = $user.username + Name = $user.fullname + Email = $user.email + Status = $user.status + PasswordStatus = $user.passwordstatus + Role = $user.role + } + $userResults += $userString + } catch { + Write-Error $Error[0].exception.Message + } + } else { + $users = $userAPI.list() + + foreach ($user in $users) { + $userString = [pscustomobject] @{ + User = $user.username + Name = $user.fullname + Email = $user.email + Status = $user.status + PasswordStatus = $user.passwordstatus + Role = $user.role + } + $userResults += $userString + } + } + $userResults +} + +Function New-VAMIUser { +<# + .NOTES + =========================================================================== + Created by: William Lam + Organization: VMware + Blog: www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + .SYNOPSIS + This function to create new VAMI local user using VAMI interface (5480) + for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. + .DESCRIPTION + Function to create a new VAMI local user + .EXAMPLE + Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! + New-VAMIUser -name lamw -fullname "William Lam" -role "operator" -email "lamw@virtuallyghetto.com" -password "VMware1!" +#> + param( + [Parameter( + Mandatory=$true) + ] + [String]$name, + [Parameter( + Mandatory=$true) + ] + [String]$fullname, + [Parameter( + Mandatory=$true) + ] + [ValidateSet("admin","operator","superAdmin")][String]$role, + [Parameter( + Mandatory=$false) + ] + [String]$email="", + [Parameter( + Mandatory=$true) + ] + [String]$password + ) + + $userAPI = Get-CisService 'com.vmware.appliance.techpreview.localaccounts.user' + $createSpec = $userAPI.Help.add.config.CreateExample() + + $createSpec.username = $name + $createSpec.fullname = $fullname + $createSpec.role = $role + $createSpec.email = $email + $createSpec.password = [VMware.VimAutomation.Cis.Core.Types.V1.Secret]$password + + try { + Write-Host "Creating new user $name ..." + $userAPI.add($createSpec) + } catch { + Write-Error $Error[0].exception.Message + } +} + +Function Remove-VAMIUser { +<# + .NOTES + =========================================================================== + Created by: William Lam + Organization: VMware + Blog: www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + .SYNOPSIS + This function to remove VAMI local user using VAMI interface (5480) + for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. + .DESCRIPTION + Function to remove VAMI local user + .EXAMPLE + Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! + Get-VAMIAccess +#> + param( + [Parameter( + Mandatory=$true) + ] + [String]$name, + [Parameter( + Mandatory=$false) + ] + [boolean]$confirm=$false + ) + + if(!$confirm) { + $answer = Read-Host -Prompt "Do you want to delete user $name (Y or N)" + if($answer -eq "Y" -or $answer -eq "y") { + $userAPI = Get-CisService 'com.vmware.appliance.techpreview.localaccounts.user' + + try { + Write-Host "Deleting user $name ..." + $userAPI.delete($name) + } catch { + Write-Error $Error[0].exception.Message + } + } + } } \ No newline at end of file From 492f89cc91cc84fb27909bcd220da91747fb0312 Mon Sep 17 00:00:00 2001 From: William Lam Date: Tue, 7 Mar 2017 07:59:26 -0800 Subject: [PATCH 18/24] Adding Proactive HA Module --- Modules/ProactiveHA.psm1 | 468 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 468 insertions(+) create mode 100644 Modules/ProactiveHA.psm1 diff --git a/Modules/ProactiveHA.psm1 b/Modules/ProactiveHA.psm1 new file mode 100644 index 0000000..ea4e92f --- /dev/null +++ b/Modules/ProactiveHA.psm1 @@ -0,0 +1,468 @@ +Function New-PHAProvider { +<# + .NOTES + =========================================================================== + Created by: William Lam + Organization: VMware + Blog: www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + .DESCRIPTION + Function to register a new Proactive HA Provider with vCenter Server + .PARAMETER ProviderName + Name of ProactiveHA Provider + .PARAMETER ComponentType + Name of a supported ComponentType that ProactiveHA supports (Fan, Memory, Network, Power or Storage) + .PARAMETER ComponentDescription + Description of the health check for the given component + .PARAMETER ComponentId + Unique identifier for the given component within a ProactiveHA Provider + .EXAMPLE + New-PHAProvider -ProviderName "virtuallyGhetto" -ComponentType Power -ComponentDescription "Simulated ProactiveHA Provider" -ComponentId "Power" +#> + param( + [Parameter(Mandatory=$true)][String]$ProviderName, + [Parameter(Mandatory=$true)][ValidateSet("Fan","Memory","Network","Power","Storage")][String]$ComponentType, + [Parameter(Mandatory=$true)][String]$ComponentDescription, + [Parameter(Mandatory=$true)][String]$ComponentId + ) + Write-Host -ForegroundColor Red "`n******************** DISCLAIMER ********************" + Write-Host -ForegroundColor Red "**** THIS IS NOT INTENDED FOR PRODUCTION USE ****" + Write-Host -ForegroundColor Red "**** LEARNING PURPOSES ONLY ****" + Write-Host -ForegroundColor Red "******************** DISCLAIMER ********************`n" + + $healthManager = Get-View $global:DefaultVIServer.ExtensionData.Content.HealthUpdateManager + + $healthInfo = [VMware.Vim.HealthUpdateInfo] @{ + ComponentType = $ComponentType + description = $ComponentDescription + Id = $ComponentId + } + + try { + Write-Host "`nRegistering new Proactive HA Provider $ProviderName ..." + $providerId = $healthManager.RegisterHealthUpdateProvider($ProviderName,$healthInfo) + } catch { + Write-host -ForegroundColor Red $Error[0].Exception + } +} + +Function Get-PHAProvider { +<# + .NOTES + =========================================================================== + Created by: William Lam + Organization: VMware + Blog: www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + .DESCRIPTION + Function to return list of all Proactive HA Providers registered with vCenter Server + .EXAMPLE + Get-PHAProvider +#> + $healthManager = Get-View $global:DefaultVIServer.ExtensionData.Content.HealthUpdateManager + + $healthProviderResults = @() + $hpIDs = $healthManager.QueryProviderList() + + foreach ($hpID in $hpIDs) { + $hpName = $healthManager.QueryProviderName($hpID) + $hpConfig = $healthManager.QueryHealthUpdateInfos($hpID) + + $hp = [pscustomobject] @{ + ProviderName = $hpName + ProviderID = $hpID + ComponentType = $hpConfig.componentType + ComponentID = $hpConfig.id + Description = $hpConfig.description + } + $healthProviderResults+=$hp + } + $healthProviderResults +} + +Function Remove-PHAProvider { +<# + .NOTES + =========================================================================== + Created by: William Lam + Organization: VMware + Blog: www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + .DESCRIPTION + Function to remove a registered Proactive HA Provider from vCenter Server + .PARAMETER ProviderId + The ProactiveHA provider ID (retrieved from Get-PHAProvider) to unregister + .EXAMPLE + Remove-PHAProvider -ProviderID "52 85 22 c2 f2 6a e7 b9-fc ff 63 9e 10 81 00 79" +#> + param( + [Parameter(Mandatory=$true)][String]$ProviderId + ) + + Write-Host -ForegroundColor Red "`n******************** DISCLAIMER ********************" + Write-Host -ForegroundColor Red "**** THIS IS NOT INTENDED FOR PRODUCTION USE ****" + Write-Host -ForegroundColor Red "**** LEARNING PURPOSES ONLY ****" + Write-Host -ForegroundColor Red "******************** DISCLAIMER ********************`n" + + $healthManager = Get-View $global:DefaultVIServer.ExtensionData.Content.HealthUpdateManager + + try { + Write-Host "`nUnregistering Proactive HA Provider $ProviderId ... " + $healthManager.UnregisterHealthUpdateProvider($providerId) + } catch { + if($Error[0].Exception.InnerException.MethodFault.getType().Name -eq "InvalidState") { + Write-host -ForegroundColor Red "The Proactive HA Provider is still in use, please disable it before unregistering" + } else { + Write-host -ForegroundColor Red $Error[0].Exception + } + } +} + +Function Set-PHAConfig { +<# + .NOTES + =========================================================================== + Created by: William Lam + Organization: VMware + Blog: www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + .DESCRIPTION + Function to enable/disable Proactive HA for vSphere Cluster + .PARAMETER Cluster + Name of the vSphere Cluster to enable Proactive HA + .PARAMETER ProviderId + Proactive HA Provider ID to enable in vSphere Cluster + .PARAMETER ClusterMode + Whether Proactive HA should be "Automated" or "Manual" for actions it will take + .PARAMETER ModerateRemediation + Type of operation (Maintenance Mode or Quaratine Mode) to perform when a Moderate issue is observed + .PARAMETER SevereRemediation + Type of operation (Maintenance Mode or Quaratine Mode) to perform when a Severe issue is observed + .EXAMPLE + Set-PHAConfig -Cluster VSAN-Cluster -Enabled -ClusterMode Automated -ModerateRemediation QuarantineMode -SevereRemediation QuarantineMode -ProviderID "52 85 22 c2 f2 6a e7 b9-fc ff 63 9e 10 81 00 79" + .EXAMPLE + Set-PHAConfig -Cluster VSAN-Cluster -Disabled -ProviderID "52 85 22 c2 f2 6a e7 b9-fc ff 63 9e 10 81 00 79" +#> + param( + [Parameter(Mandatory=$true)][String]$ProviderId, + [Parameter(Mandatory=$true)][String]$Cluster, + [Parameter(Mandatory=$false)][ValidateSet("Automated","Manual")]$ClusterMode="Manual", + [Parameter(Mandatory=$false)][ValidateSet("MaintenanceMode","QuarantineMode")]$ModerateRemediation="QuarantineMode", + [Parameter(Mandatory=$false)][ValidateSet("MaintenanceMode","QuarantineMode")]$SevereRemediation="QuarantineMode", + [Switch]$Enabled, + [Switch]$Disabled + ) + + $ClusterView = Get-View -ViewType ClusterComputeResource -Property Name,Host,ConfigurationEx -Filter @{"Name" = $Cluster} + + if($ClusterView -eq $null) { + Write-Host -ForegroundColor Red "Unable to find vSphere Cluster $cluster ..." + break + } + + $vmhosts = $ClusterView.host + + $healthManager = Get-View $global:DefaultVIServer.ExtensionData.Content.HealthUpdateManager + + if($Enabled) { + try { + $entities = @() + foreach ($vmhost in $vmhosts) { + if(-not $healthManager.HasMonitoredEntity($ProviderId,$vmhost)) { + $entities += $vmhost + } + } + + Write-Host "Enabling Proactive HA monitoring for all ESXi hosts in cluster ..." + $healthManager.AddMonitoredEntities($ProviderId,$entities) + } catch { + Write-host -ForegroundColor Red $Error[0].Exception + } + + try { + $healthProviders = @() + + # Make sure not to remove existing ProactiveHA providers + if($ClusterView.ConfigurationEx.InfraUpdateHaConfig.Providers -ne $null) { + $currentHPs = $ClusterView.ConfigurationEx.infraUpdateHaConfig.providers + foreach ($currentHP in $currentHPs) { + $healthProviders+=$currentHP + } + if(-not ($healthProviders -contains $ProviderID)) { + $healthProviders+=$ProviderId + } + } else { + $healthProviders+=$ProviderId + } + + $PHASpec = [VMware.Vim.ClusterInfraUpdateHaConfigInfo] @{ + enabled = $true + behavior = $ClusterMode + moderateRemediation = $ModerateRemediation + severeRemediation = $SevereRemediation + providers = $healthProviders + } + + $spec = [VMware.Vim.ClusterConfigSpecEx] @{ + infraUpdateHaConfig = $PHASpec + } + + Write-Host "Enabling Proactive HA Provider $ProviderId on $Cluster ..." + $task = $ClusterView.ReconfigureComputeResource_Task($spec,$True) + $task1 = Get-Task -Id ("Task-$($task.value)") + $task1 | Wait-Task | Out-Null + } catch { + Write-host -ForegroundColor Red $Error[0].Exception + } + } + + if($Disabled) { + foreach ($vmhost in $vmhosts) { + if($vmhost.runtime.inQuarantineMode) { + Write-Host -ForegroundColor Red $vmhost.name " is currently still in Quaratine Mode, please remediate this before disabling Proactive HA" + break + } + } + + try { + $healthProviders = @() + + # Make sure not to remove existing ProactiveHA providers + if($ClusterView.ConfigurationEx.InfraUpdateHaConfig.Providers -ne $null) { + $currentHPs = $ClusterView.ConfigurationEx.infraUpdateHaConfig.providers + foreach ($currentHP in $currentHPs) { + if($currentHP -ne $ProviderId) { + $healthProviders+=$currentHP + } + } + } + + $PHASpec = [VMware.Vim.ClusterInfraUpdateHaConfigInfo] @{ + enabled = $true + behavior = $ClusterMode + moderateRemediation = $ModerateRemediation + severeRemediation = $SevereRemediation + providers = $healthProviders + } + + $spec = [VMware.Vim.ClusterConfigSpecEx] @{ + infraUpdateHaConfig = $PHASpec + } + + Write-Host "Disabling Proactive HA Provider $ProviderId on $Cluster ..." + $task = $ClusterView.ReconfigureComputeResource_Task($spec,$True) + $task1 = Get-Task -Id ("Task-$($task.value)") + $task1 | Wait-Task | Out-Null + } catch { + Write-host -ForegroundColor Red $Error[0].Exception + } + + $ClusterView.UpdateViewData() + + try { + $entities = @() + foreach ($vmhost in $vmhosts) { + if($healthManager.HasMonitoredEntity($ProviderId,$vmhost)) { + $entities += $vmhost + } + } + + Write-Host "Disabling Proactive HA monitoring for all ESXi hosts in cluster ..." + $healthManager.RemoveMonitoredEntities($ProviderId,$entities) + } catch { + Write-host -ForegroundColor Red $Error[0].Exception + } + } +} + +Function Get-PHAConfig { +<# + .NOTES + =========================================================================== + Created by: William Lam + Organization: VMware + Blog: www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + .DESCRIPTION + Function to retrieve Proactive HA configuration for a vSphere Cluster + .PARAMETER Cluster + Name of the vSphere Cluster to check Proactive HA configuration + .EXAMPLE + Get-PHAConfig -Cluster VSAN-Cluster +#> + param( + [Parameter(Mandatory=$true)][String]$Cluster + ) + + $ClusterView = Get-View -ViewType ClusterComputeResource -Property Name,ConfigurationEx -Filter @{"Name" = $Cluster} + + if($ClusterView -eq $null) { + Write-Host -ForegroundColor Red "Unable to find vSphere Cluster $cluster ..." + break + } + + if($ClusterView.ConfigurationEx.InfraUpdateHaConfig.Providers -ne $null) { + $healthManager = Get-View $global:DefaultVIServer.ExtensionData.Content.HealthUpdateManager + + $phSettings = $ClusterView.ConfigurationEx.InfraUpdateHaConfig + $providers = $ClusterView.ConfigurationEx.InfraUpdateHaConfig.Providers + $healthProviders = @() + foreach ($provider in $providers) { + $providerName = $healthManager.QueryProviderName($provider) + $healthProviders+=$providerName + } + + $pHAConfig = [pscustomobject] @{ + Enabled = $phSettings.Enabled + ClusterMode = $phSettings.behavior + ModerateRemediation = $phSettings.ModerateRemediation + SevereRemediation = $phSettings.SevereRemediation + HealthProviders = $healthProviders + } + $pHAConfig + } else { + Write-Host "Proactive HA has not been configured on this vSphere Cluster" + } +} + +Function Get-PHAHealth { +<# + .NOTES + =========================================================================== + Created by: William Lam + Organization: VMware + Blog: www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + .DESCRIPTION + Function to retrieve the Proactive HA health info for all ESXi hosts in vSphere Cluster + .PARAMETER Cluster + Name of the vSphere Cluster to check Proactive HA health information + .EXAMPLE + Get-PHAHealth -Cluster VSAN-Cluster +#> + param( + [Parameter(Mandatory=$true)][String]$Cluster + ) + + $ClusterView = Get-View -ViewType ClusterComputeResource -Property Name,ConfigurationEx -Filter @{"Name" = $Cluster} + + if($ClusterView -eq $null) { + Write-Host -ForegroundColor Red "Unable to find vSphere Cluster $cluster ..." + break + } + + if($ClusterView.ConfigurationEx.InfraUpdateHaConfig.Providers -ne $null) { + $healthManager = Get-View $global:DefaultVIServer.ExtensionData.Content.HealthUpdateManager + + $providers = $ClusterView.ConfigurationEx.InfraUpdateHaConfig.Providers + + foreach ($provider in $providers) { + $providerName = $healthManager.QueryProviderName($provider) + $healthUpdates = $healthManager.QueryHealthUpdates($provider) + + $healthResults = @() + Write-Host -NoNewline -ForegroundColor Magenta "Health summary for Proactive HA Provider $providerName`:`n" + foreach ($healthUpdate in $healthUpdates) { + $vmhost = Get-View $healthUpdate.Entity + + $hr = [PSCustomObject] @{ + Entity = $vmhost.name + Status = $healthUpdate.status + HealthComponentId = $healthUpdate.HealthUpdateInfoId + HealthUpdateId = $healthUpdate.Id + Remediation = $healthUpdate.Remediation + } + $healthResults+=$hr + } + $healthResults + } + } else { + Write-Host "Proactive HA has not been configured on this vSphere Cluster" + } +} + +Function New-PHASimulation { +<# + .NOTES + =========================================================================== + Created by: William Lam + Organization: VMware + Blog: www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + .DESCRIPTION + Function to return VCHA Configuration + .PARAMETER ProviderId + The Proactive HA Provider ID that you like to simulate a health update from + .PARAMETER EsxiHost + The name of ESXi host to update the health on + .PARAMETER Component + The name of the matching component ID from Proactive HA Provider to simulate a health update from + .PARAMETER HealthStatus + The health value (green, yellow or red) for the given simulated health Update + .PARAMETER Remediation + The remediation message associated with simulated health update + .EXAMPLE + New-PHASimulation -EsxiHost vesxi65-4.primp-industries.com -Component Power -HealthStatus green -Remediation "" -ProviderId "52 85 22 c2 f2 6a e7 b9-fc ff 63 9e 10 81 00 79" + .EXAMPLE + New-PHASimulation -EsxiHost vesxi65-4.primp-industries.com -Component Power -HealthStatus red -Remediation "Please replace my virtual PSU" -ProviderId "52 85 22 c2 f2 6a e7 b9-fc ff 63 9e 10 81 00 79" +#> + param( + [Parameter(Mandatory=$true)][String]$ProviderId, + [Parameter(Mandatory=$true)][String]$EsxiHost, + [Parameter(Mandatory=$true)][String]$Component, + [Parameter(Mandatory=$true)][ValidateSet("green","red","yellow")][String]$HealthStatus, + [Parameter(Mandatory=$false)][String]$Remediation + ) + + Write-Host -ForegroundColor Red "`n******************** DISCLAIMER ********************" + Write-Host -ForegroundColor Red "**** THIS IS NOT INTENDED FOR PRODUCTION USE ****" + Write-Host -ForegroundColor Red "**** LEARNING PURPOSES ONLY ****" + Write-Host -ForegroundColor Red "******************** DISCLAIMER ********************`n" + + $vmhost = Get-View -ViewType HostSystem -Property Name -Filter @{"name" = $EsxiHost} + + if($vmhost -eq $null) { + Write-Host -ForegroundColor Red "`nUnable to find ESXi host $EsxiHost ..." + break + } + + $healthManager = Get-View $global:DefaultVIServer.ExtensionData.Content.HealthUpdateManager + + # Randomly generating an ID for Health Update + # In general, you would want to generate a specific ID + # which can be referenced between ProactiveHA Provider + # and VMware logs for troubleshooting purposes + $HealthUpdateID = "vghetto-" + (Get-Random -Minimum 1 -Maximum 100000) + + # All other Health Status can have a remediation message + # but for green, it must be an empty string or API call will fail + if($HealthStatus -eq "green") { + $Remediation = "" + } + + $healthUpdate = [VMware.Vim.HealthUpdate] @{ + Entity = $vmhost.moref + HealthUpdateInfoId = $Component + Id = $HealthUpdateId + Status = $HealthStatus + Remediation = $Remediation + } + + try { + Write-Host "`nSimulating Proactive HA Health Update to ..." + Write-Host "`tHost: $EsxiHost " + Write-Host -NoNewline "`tStatus: " + Write-Host -ForegroundColor $HealthStatus "$HealthStatus" + Write-Host "`tRemediation Messsage: $Remediation" + $healthManager.PostHealthUpdates($providerId,$healthUpdate) + } catch { + Write-host -ForegroundColor Red $Error[0].Exception + } +} \ No newline at end of file From fe738ba17ad835491ccba2ebf711751b8369c6d5 Mon Sep 17 00:00:00 2001 From: Ray Heffer Date: Tue, 18 Apr 2017 11:19:03 -0400 Subject: [PATCH 19/24] Create Horizon-UsageStats.ps1 This is a sample script that retrieves the Horizon usage statistics. --- Scripts/Horizon-UsageStats.ps1 | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Scripts/Horizon-UsageStats.ps1 diff --git a/Scripts/Horizon-UsageStats.ps1 b/Scripts/Horizon-UsageStats.ps1 new file mode 100644 index 0000000..7c389bb --- /dev/null +++ b/Scripts/Horizon-UsageStats.ps1 @@ -0,0 +1,38 @@ +<# +.NOTES +Script name: Horizon-UsageStats.ps1 +Author: Ray Heffer, @rayheffer +Last Edited on: 04/18/2017 +Dependencies: PowerCLI 6.5 R1 or later, Horizon 7.0.2 or later +.DESCRIPTION +This is a sample script that retrieves the Horizon usage statistics. This produces the same metrics as listed under View Configuration > Product Licensing and Usage. Service providers can use this script or incorporate it with their existing scripts to automate the reporting of Horizon usage. + +Example Output: +NumConnections : 180 +NumConnectionsHigh : 250 +NumViewComposerConnections : 0 +NumViewComposerConnectionsHigh : 0 +NumTunneledSessions : 0 +NumPSGSessions : 180 +#> + +# User Configuration +$hzUser = "Administrator" +$hzPass = "VMware1!" +$hzDomain = "vmw.lab" +$hzConn = "connect01.vmw.lab" + +# Import the Horizon module +Import-Module VMware.VimAutomation.HorizonView + +# Establish connection to Connection Server +$hvServer = Connect-HVServer -server $hzConn -User $hzUser -Password $hzPass -Domain $hzDomain + +# Assign a variable to obtain the API Extension Data +$hvServices = $Global:DefaultHVServers.ExtensionData + +# Retrieve Connection Server Health metrics +$hvHealth =$hvServices.ConnectionServerHealth.ConnectionServerHealth_List() + +# Display ConnectionData (Usage stats) +$hvHealth.ConnectionData From bd2edd6bd935a3659fd81250fdf4082bcf483c84 Mon Sep 17 00:00:00 2001 From: Ray Heffer Date: Tue, 18 Apr 2017 16:55:21 -0400 Subject: [PATCH 20/24] Rename Horizon-UsageStats.ps1 to Horizon-GetUsageStats.ps1 --- Scripts/{Horizon-UsageStats.ps1 => Horizon-GetUsageStats.ps1} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Scripts/{Horizon-UsageStats.ps1 => Horizon-GetUsageStats.ps1} (100%) diff --git a/Scripts/Horizon-UsageStats.ps1 b/Scripts/Horizon-GetUsageStats.ps1 similarity index 100% rename from Scripts/Horizon-UsageStats.ps1 rename to Scripts/Horizon-GetUsageStats.ps1 From 5aee669b4cbcb6feb058d2ca1b88fa92661e6d38 Mon Sep 17 00:00:00 2001 From: Alan Renouf Date: Tue, 18 Apr 2017 21:03:53 -0700 Subject: [PATCH 21/24] create modules.sh added modules file for copying to powerclicore correct locations --- Scripts/modules.sh | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Scripts/modules.sh diff --git a/Scripts/modules.sh b/Scripts/modules.sh new file mode 100644 index 0000000..ea84779 --- /dev/null +++ b/Scripts/modules.sh @@ -0,0 +1,6 @@ +#!/bin/bash +for file in $( ls /powershell/PowerCLI-Example-Scripts/Modules/ ) +do + mkdir "/root/.local/share/powershell/Modules/${file%.*}/" + mv "/powershell/PowerCLI-Example-Scripts/Modules/$file" "/root/.local/share/powershell/Modules/${file%.*}/$file" +done From 3c18981280755af61aac7820d5667576724f8f0e Mon Sep 17 00:00:00 2001 From: Alan Renouf Date: Thu, 20 Apr 2017 11:59:08 -0700 Subject: [PATCH 22/24] updated pester tests and uncluded new ones for CIS cmdlets --- ...nnect-CISServer Connection to VC.Tests.ps1 | 37 ++++++++++++++++ ...onnect-VIServer Connection to VC.Tests.ps1 | 36 +++++++++++++++ Pester/Test Connection to VC.ps1 | 44 ------------------- .../Test Disconnect-CISServer to VC.Tests.ps1 | 20 +++++++++ .../Test Disconnect-VIServer to VC.Tests.ps1 | 20 +++++++++ 5 files changed, 113 insertions(+), 44 deletions(-) create mode 100644 Pester/Test Connect-CISServer Connection to VC.Tests.ps1 create mode 100644 Pester/Test Connect-VIServer Connection to VC.Tests.ps1 delete mode 100644 Pester/Test Connection to VC.ps1 create mode 100644 Pester/Test Disconnect-CISServer to VC.Tests.ps1 create mode 100644 Pester/Test Disconnect-VIServer to VC.Tests.ps1 diff --git a/Pester/Test Connect-CISServer Connection to VC.Tests.ps1 b/Pester/Test Connect-CISServer Connection to VC.Tests.ps1 new file mode 100644 index 0000000..e9fb3c9 --- /dev/null +++ b/Pester/Test Connect-CISServer Connection to VC.Tests.ps1 @@ -0,0 +1,37 @@ +<# +Script name: Test Connect-CISServer to VC.Tests.ps1 +Created on: 04/20/2017 +Author: Alan Renouf, @alanrenouf +Description: The purpose of this pester test is to ensure the PowerCLI modules are imported and a connection can be made to a vCenter for the CIS Service +Dependencies: Pester Module +Example run: + +Invoke-Pester -Script @{ Path = '.\Test Connect-CISServer to VC.Tests.ps1'; Parameters = @{ VCNAME="VC01.local"; VCUSER="Administrator@vsphere.local"; VCPASS="Admin!23"} } + +#> + +$VCUSER = $Parameters.Get_Item("VCUSER") +$VCPASS = $Parameters.Get_Item("VCPASS") +$VCNAME = $Parameters.Get_Item("VCNAME") + +Describe "Checking PowerCLI Cmdlets available" { + $cmdletname = "Connect-CISServer" + It "Checking $cmdletname is available" { + $command = Get-Command $cmdletname + $command | Select Name, Version + $command.Name| Should Be $cmdletname + } +} + +Describe "Connect-CISServer Tests" { + + $connection = Connect-CISServer $VCName -User $VCUser -password $VCPass + It "Connection is active" { + $Global:DefaultCISServers[0].isconnected | Should Be $true + } + + It "Checking connected server name is $VCName" { + $Global:DefaultCISServers[0] | Select * + $Global:DefaultCISServers[0].name | Should Be $VCName + } +} \ No newline at end of file diff --git a/Pester/Test Connect-VIServer Connection to VC.Tests.ps1 b/Pester/Test Connect-VIServer Connection to VC.Tests.ps1 new file mode 100644 index 0000000..2428458 --- /dev/null +++ b/Pester/Test Connect-VIServer Connection to VC.Tests.ps1 @@ -0,0 +1,36 @@ +<# +Script name: Test Connection to VC.ps1 +Created on: 07/15/2016 +Author: Alan Renouf, @alanrenouf +Description: The purpose of this pester test is to ensure the PowerCLI modules are imported and a connection can be made to a vCenter +Dependencies: Pester Module +Example run: + +Invoke-Pester -Script @{ Path = '.\Test Connection to VC.Tests.ps1'; Parameters = @{ VCNAME="VC01.local"; VCUSER="Administrator@vsphere.local"; VCPASS="Admin!23"} } + +#> + +$VCUSER = $Parameters.Get_Item("VCUSER") +$VCPASS = $Parameters.Get_Item("VCPASS") +$VCNAME = $Parameters.Get_Item("VCNAME") + +Describe "Checking PowerCLI Cmdlets available" { + $cmdletname = "Connect-VIServer" + It "Checking $cmdletname is available" { + $command = Get-Command $cmdletname + $command | Select Name, Version + $command.Name| Should Be $cmdletname + } +} + +Describe "Connect-VIServer Tests" { + + $connection = Connect-VIServer $VCName -User $VCUser -password $VCPass + It "Connection is active" { + $Global:DefaultVIServer[0].isconnected | Should Be $true + } + + It "Checking connected server name is $VCName" { + $Global:DefaultVIServer[0].name | Should Be $VCName + } +} \ No newline at end of file diff --git a/Pester/Test Connection to VC.ps1 b/Pester/Test Connection to VC.ps1 deleted file mode 100644 index 006825a..0000000 --- a/Pester/Test Connection to VC.ps1 +++ /dev/null @@ -1,44 +0,0 @@ -<# -Script name: Test Connection to VC.ps1 -Created on: 07/15/2016 -Author: Alan Renouf, @alanrenouf -Description: The purpose of this pester test is to ensure the PowerCLI modules are imported and a connection and disconnection can be made to a vCenter -Dependencies: Pester Module -Example run: - -Invoke-Pester -Script @{ Path = '.\Test Connection to VC.ps1'; Parameters = @{ VCNAME="VC01.local"; VCUSER="Administrator@vsphere.local"; VCPASS="Admin!23"} } - -#> - -$VCUSER = $Parameters.Get_Item("VCUSER") -$VCPASS = $Parameters.Get_Item("VCPASS") -$VCNAME = $Parameters.Get_Item("VCNAME") - -Describe "PowerCLI Tests" { - It "Importing PowerCLI Modules" { - Get-Module VMware* | Foreach { - Write-Host "Importing Module $($_.name) Version $($_.Version)" - $_ | Import-Module - Get-Module $_ | Should Be $true - } - } -} - -Describe "Connect-VIServer Tests" { - - $connection = Connect-VIServer $VCName -User $VCUser -password $VCPass - It "Connection is active" { - $Global:DefaultVIServer[0].isconnected | Should Be $true - } - - It "Checking connected server name is $VCName" { - $Global:DefaultVIServer[0].name | Should Be $VCName - } -} - -Describe "Disconnect-VIServer Tests" { - It "Disconnect from $VCName" { - Disconnect-VIServer $VCName -confirm:$false - $Global:DefaultVIServer | Should Be $null - } -} \ No newline at end of file diff --git a/Pester/Test Disconnect-CISServer to VC.Tests.ps1 b/Pester/Test Disconnect-CISServer to VC.Tests.ps1 new file mode 100644 index 0000000..63f12e4 --- /dev/null +++ b/Pester/Test Disconnect-CISServer to VC.Tests.ps1 @@ -0,0 +1,20 @@ +<# +Script name: Test Disconnect-CISServer to VC.Tests.ps1 +Created on: 04/20/2017 +Author: Alan Renouf, @alanrenouf +Description: The purpose of this pester test is to ensure the Disconnect-CISServer cmdlet disconnects +Dependencies: Pester Module +Example run: + +Invoke-Pester -Script @{ Path = '.\Test Disconnect-CISServer to VC.Tests.ps1'; Parameters = @{ VCNAME="VC01.local" } } + +#> + +$VCNAME = $Parameters.Get_Item("VCNAME") + +Describe "Disconnect-CISServer Tests" { + It "Disconnect from $VCName" { + Disconnect-CISServer $VCName -confirm:$false + $Global:DefaultCISServers | Should Be $null + } +} \ No newline at end of file diff --git a/Pester/Test Disconnect-VIServer to VC.Tests.ps1 b/Pester/Test Disconnect-VIServer to VC.Tests.ps1 new file mode 100644 index 0000000..8a51fb9 --- /dev/null +++ b/Pester/Test Disconnect-VIServer to VC.Tests.ps1 @@ -0,0 +1,20 @@ +<# +Script name: Test Disconnect-VIServer to VC.ps1 +Created on: 04/20/2017 +Author: Alan Renouf, @alanrenouf +Description: The purpose of this pester test is to ensure the Disconnect-VIServer cmdlet disconnects +Dependencies: Pester Module +Example run: + +Invoke-Pester -Script @{ Path = '.\Test Disconnect-VISServer to VC.ps1'; Parameters = @{ VCNAME="VC01.local" } } + +#> + +$VCNAME = $Parameters.Get_Item("VCNAME") + +Describe "Disconnect-VIServer Tests" { + It "Disconnect from $VCName" { + Disconnect-VIServer $VCName -confirm:$false + $Global:DefaultVIServer | Should Be $null + } +} \ No newline at end of file From 29578c6305c8cc7c7f381798f22553f8bd9d7b65 Mon Sep 17 00:00:00 2001 From: Alan Renouf Date: Thu, 20 Apr 2017 16:24:40 -0700 Subject: [PATCH 23/24] updated pester tests for CIS cmdlets --- ...nect-CISServer Connection to VC.Tests.ps1} | 0 ...nnect-VIServer Connection to VC.Tests.ps1} | 0 Pester/Test Get-CISService.Tests.ps1 | 49 +++++++++++++++++++ ...Test Disconnect-CISServer to VC.Tests.ps1} | 0 ... Test Disconnect-VIServer to VC.Tests.ps1} | 0 5 files changed, 49 insertions(+) rename Pester/{Test Connect-CISServer Connection to VC.Tests.ps1 => 00 Test Connect-CISServer Connection to VC.Tests.ps1} (100%) rename Pester/{Test Connect-VIServer Connection to VC.Tests.ps1 => 00 Test Connect-VIServer Connection to VC.Tests.ps1} (100%) create mode 100644 Pester/Test Get-CISService.Tests.ps1 rename Pester/{Test Disconnect-CISServer to VC.Tests.ps1 => ZZ Test Disconnect-CISServer to VC.Tests.ps1} (100%) rename Pester/{Test Disconnect-VIServer to VC.Tests.ps1 => ZZ Test Disconnect-VIServer to VC.Tests.ps1} (100%) diff --git a/Pester/Test Connect-CISServer Connection to VC.Tests.ps1 b/Pester/00 Test Connect-CISServer Connection to VC.Tests.ps1 similarity index 100% rename from Pester/Test Connect-CISServer Connection to VC.Tests.ps1 rename to Pester/00 Test Connect-CISServer Connection to VC.Tests.ps1 diff --git a/Pester/Test Connect-VIServer Connection to VC.Tests.ps1 b/Pester/00 Test Connect-VIServer Connection to VC.Tests.ps1 similarity index 100% rename from Pester/Test Connect-VIServer Connection to VC.Tests.ps1 rename to Pester/00 Test Connect-VIServer Connection to VC.Tests.ps1 diff --git a/Pester/Test Get-CISService.Tests.ps1 b/Pester/Test Get-CISService.Tests.ps1 new file mode 100644 index 0000000..17d18b5 --- /dev/null +++ b/Pester/Test Get-CISService.Tests.ps1 @@ -0,0 +1,49 @@ +<# +Script name: Test Connect-CISService.Tests.ps1 +Created on: 04/20/2017 +Author: Alan Renouf, @alanrenouf +Description: The purpose of this pester test is to ensure the CIS Service cmdlet works correctly +Dependencies: Pester Module +Example run: + +Invoke-Pester -Script @{ Path = '.\Test Get-CISService.ps1' } + +#> + +Describe "Checking PowerCLI Cmdlets available" { + $cmdletname = "Get-CISService" + It "Checking $cmdletname is available" { + $command = Get-Command $cmdletname + $command | Select Name, Version + $command.Name| Should Be $cmdletname + } +} + +Describe "Get-CISService Tests for services" { + + It "Checking CIS connection is active" { + $Global:DefaultCISServers[0].isconnected | Should Be $true + } + + It "Checking Get-CISService returns services" { + Get-CISService | Should Be $true + } + + # Checking some known services which have a Get Method + $servicestocheck = "com.vmware.appliance.system.version", "com.vmware.appliance.health.system" + Foreach ($service in $servicestocheck) { + It "Checking $service get method returns data" { + Get-CisService -Name $service | Should Be $true + (Get-CisService -Name $service).get() | Should Be $true + } + } + + # Checking some known services which have a List Method + $servicestocheck = "com.vmware.vcenter.folder", "com.vmware.vcenter.vm" + Foreach ($service in $servicestocheck) { + It "Checking $service list method returns data" { + Get-CisService -Name $service | Should Be $true + (Get-CisService -Name $service).list() | Should Be $true + } + } +} \ No newline at end of file diff --git a/Pester/Test Disconnect-CISServer to VC.Tests.ps1 b/Pester/ZZ Test Disconnect-CISServer to VC.Tests.ps1 similarity index 100% rename from Pester/Test Disconnect-CISServer to VC.Tests.ps1 rename to Pester/ZZ Test Disconnect-CISServer to VC.Tests.ps1 diff --git a/Pester/Test Disconnect-VIServer to VC.Tests.ps1 b/Pester/ZZ Test Disconnect-VIServer to VC.Tests.ps1 similarity index 100% rename from Pester/Test Disconnect-VIServer to VC.Tests.ps1 rename to Pester/ZZ Test Disconnect-VIServer to VC.Tests.ps1 From a3c91c6376b77ce274cd5aae2e02c501a37e0023 Mon Sep 17 00:00:00 2001 From: William Lam Date: Thu, 20 Apr 2017 17:47:31 -0700 Subject: [PATCH 24/24] Adding vSAN Mgmt 6.x PowerCLI samples --- Scripts/VSANSmartsData.ps1 | 59 ++++++++++++++++++++++++++++++++++++++ Scripts/VSANVersion.ps1 | 26 +++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 Scripts/VSANSmartsData.ps1 create mode 100644 Scripts/VSANVersion.ps1 diff --git a/Scripts/VSANSmartsData.ps1 b/Scripts/VSANSmartsData.ps1 new file mode 100644 index 0000000..61ef427 --- /dev/null +++ b/Scripts/VSANSmartsData.ps1 @@ -0,0 +1,59 @@ +Function Get-VSANSmartsData { +<# + .NOTES + =========================================================================== + Created by: William Lam + Organization: VMware + Blog: www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + .DESCRIPTION + This function retreives SMART drive data using new vSAN + Management 6.6 API. This can also be used outside of vSAN + to query existing SSD devices not being used for vSAN. + .PARAMETER Cluster + The name of a vSAN Cluster + .EXAMPLE + Get-VSANSmartsData -Cluster VSAN-Cluster +#> + param( + [Parameter(Mandatory=$false)][String]$Cluster + ) + + if($global:DefaultVIServer.ExtensionData.Content.About.ApiType -eq "VirtualCenter") { + if(!$cluster) { + Write-Host "Cluster property is required when connecting to vCenter Server" + break + } + + $vchs = Get-VSANView -Id "VsanVcClusterHealthSystem-vsan-cluster-health-system" + $cluster_view = (Get-Cluster -Name $Cluster).ExtensionData.MoRef + $result = $vchs.VsanQueryVcClusterSmartStatsSummary($cluster_view) + } else { + $vhs = Get-VSANView -Id "HostVsanHealthSystem-ha-vsan-health-system" + $result = $vhs.VsanHostQuerySmartStats($null,$true) + } + + $vmhost = $result.Hostname + $smartsData = $result.SmartStats + + Write-Host "`nESXi Host: $vmhost`n" + foreach ($data in $smartsData) { + if($data.stats) { + $stats = $data.stats + Write-Host $data.disk + + $smartsResults = @() + foreach ($stat in $stats) { + $statResult = [pscustomobject] @{ + Parameter = $stat.Parameter; + Value =$stat.Value; + Threshold = $stat.Threshold; + Worst = $stat.Worst + } + $smartsResults+=$statResult + } + $smartsResults | Format-Table + } + } +} \ No newline at end of file diff --git a/Scripts/VSANVersion.ps1 b/Scripts/VSANVersion.ps1 new file mode 100644 index 0000000..45fa7a7 --- /dev/null +++ b/Scripts/VSANVersion.ps1 @@ -0,0 +1,26 @@ +Function Get-VSANVersion { +<# + .NOTES + =========================================================================== + Created by: William Lam + Organization: VMware + Blog: www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + .DESCRIPTION + This function retreives the vSAN software version for both VC/ESXi + .PARAMETER Cluster + The name of a vSAN Cluster + .EXAMPLE + Get-VSANVersion -Cluster VSAN-Cluster +#> + param( + [Parameter(Mandatory=$true)][String]$Cluster + ) + $vchs = Get-VSANView -Id "VsanVcClusterHealthSystem-vsan-cluster-health-system" + $cluster_view = (Get-Cluster -Name $Cluster).ExtensionData.MoRef + $results = $vchs.VsanVcClusterQueryVerifyHealthSystemVersions($cluster_view) + + Write-Host "`nVC Version:"$results.VcVersion + $results.HostResults | Select Hostname, Version +}