From 307f3d29978c80666797f8a8e3c4a8fa83f7d203 Mon Sep 17 00:00:00 2001 From: William Lam Date: Mon, 23 Jan 2017 08:00:33 -0800 Subject: [PATCH 01/17] 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/17] 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/17] 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/17] 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/17] 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/17] 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/17] 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/17] 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/17] 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/17] 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/17] 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/17] 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/17] 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/17] 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/17] 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/17] 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/17] 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