Using splat method for creating PS Objects

This commit is contained in:
William Lam
2017-02-01 08:56:02 -08:00
parent fbbdb72300
commit e3c9108ae8

View File

@@ -24,13 +24,14 @@
$ts = [timespan]::fromseconds($systemUptimeAPI.get().toString()) $ts = [timespan]::fromseconds($systemUptimeAPI.get().toString())
$uptime = $ts.ToString("hh\:mm\:ss\,fff") $uptime = $ts.ToString("hh\:mm\:ss\,fff")
$summaryResult = "" | Select Product, Type, Version, Build, InstallTime, Uptime $summaryResult = New-Object PSObject -Property @{
$summaryResult.Product = $results.product Product = $results.product;
$summaryResult.Type = $results.type Type = $results.type;
$summaryResult.Version = $results.version Version = $results.version;
$summaryResult.Build = $results.build Build = $results.build;
$summaryResult.InstallTime = $results.install_time InstallTime = $results.install_time;
$summaryResult.Uptime = $uptime Uptime = $uptime
}
$summaryResult $summaryResult
} }
@@ -71,15 +72,16 @@ Function Get-VAMIHealth {
} }
$healthSoftwareUpdates = (Get-CisService -Name 'com.vmware.appliance.health.softwarepackages').get() $healthSoftwareUpdates = (Get-CisService -Name 'com.vmware.appliance.health.softwarepackages').get()
$healthResult = "" | Select HealthOverall, HealthLastCheck, HealthCPU, HealthMem, HealthSwap, HealthStorage, HealthVCDB, HealthSoftware $healthResult = New-Object PSObject -Property @{
$healthResult.HealthOverall = $healthOverall HealthOverall = $healthOverall;
$healthResult.HealthLastCheck = $healthLastCheck HealthLastCheck = $healthLastCheck;
$healthResult.HealthCPU = $healthCPU HealthCPU = $healthCPU;
$healthResult.HealthMem = $healthMem HealthMem = $healthMem;
$healthResult.HealthSwap = $healthSwap HealthSwap = $healthSwap;
$healthResult.HealthStorage = $healthStorage HealthStorage = $healthStorage;
$healthResult.HealthVCDB = $healthVCDB HealthVCDB = $healthVCDB;
$healthResult.HealthSoftware = $healthSoftwareUpdates HealthSoftware = $healthSoftwareUpdates
}
$healthResult $healthResult
} }
@@ -108,11 +110,12 @@ Function Get-VAMIAccess {
$shellAccess = (Get-CisService -Name 'com.vmware.appliance.access.shell').get() $shellAccess = (Get-CisService -Name 'com.vmware.appliance.access.shell').get()
$sshAccess = (Get-CisService -Name 'com.vmware.appliance.access.ssh').get() $sshAccess = (Get-CisService -Name 'com.vmware.appliance.access.ssh').get()
$accessResult = "" | Select Console, DCUI, BashShell, SSH $accessResult = New-Object PSObject -Property @{
$accessResult.Console = $consoleAccess Console = $consoleAccess;
$accessResult.DCUI = $dcuiAccess DCUI = $dcuiAccess;
$accessResult.BashShell = $shellAccess.enabled BashShell = $shellAccess.enabled;
$accessResult.SSH = $sshAccess SSH = $sshAccess
}
$accessResult $accessResult
} }
@@ -139,23 +142,22 @@ Function Get-VAMITime {
$systemTimeAPI = Get-CisService -Name 'com.vmware.appliance.system.time' $systemTimeAPI = Get-CisService -Name 'com.vmware.appliance.system.time'
$timeResults = $systemTimeAPI.get() $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() $timeSync = (Get-CisService -Name 'com.vmware.appliance.techpreview.timesync').get()
$timeSyncMode = $timeSync.mode $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") { if($timeSyncMode -eq "NTP") {
$ntpServers = (Get-CisService -Name 'com.vmware.appliance.techpreview.ntp').get() $ntpServers = (Get-CisService -Name 'com.vmware.appliance.techpreview.ntp').get()
$timeResult.NTPServers = $ntpServers.servers $timeResult.NTPServers = $ntpServers.servers
$timeResult.NTPStatus = $ntpServers.status $timeResult.NTPStatus = $ntpServers.status
} else {
$timeResult.NTPServers = "N/A"
$timeResult.NTPStatus = "N/A"
} }
$timeResult $timeResult
@@ -190,22 +192,21 @@ Function Get-VAMINetwork {
$interfaces = (Get-CisService -Name 'com.vmware.appliance.networking.interfaces').list() $interfaces = (Get-CisService -Name 'com.vmware.appliance.networking.interfaces').list()
foreach ($interface in $interfaces) { 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') $ipv4API = (Get-CisService -Name 'com.vmware.appliance.techpreview.networking.ipv4')
$spec = $ipv4API.Help.get.interfaces.CreateExample() $spec = $ipv4API.Help.get.interfaces.CreateExample()
$spec+= $interface.name $spec+= $interface.name
$ipv4result = $ipv4API.get($spec) $ipv4result = $ipv4API.get($spec)
$interfaceResult.Mode = $ipv4result.mode $interfaceResult = New-Object PSObject -Property @{
$interfaceResult.IP = $ipv4result.address Inteface = $interface.name;
$interfaceResult.Prefix = $ipv4result.prefix MAC = $interface.mac;
$interfaceResult.Gateway = $ipv4result.default_gateway Status = $interface.status;
$interfaceResult.Updateable = $ipv4result.updateable Mode = $ipv4result.mode;
IP = $ipv4result.address;
Prefix = $ipv4result.prefix;
Gateway = $ipv4result.default_gateway;
Updateable = $ipv4result.updateable
}
$netResults += $interfaceResult $netResults += $interfaceResult
} }
$netResults $netResults