Merge remote-tracking branch 'refs/remotes/vmware/master'

This commit is contained in:
praveenmathamsetty
2017-04-21 21:13:04 +05:30
12 changed files with 1475 additions and 44 deletions

468
Modules/ProactiveHA.psm1 Normal file
View File

@@ -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
}
}

716
Modules/VAMI.psm1 Executable file
View File

@@ -0,0 +1,716 @@
Function Get-VAMISummary {
<#
.NOTES
===========================================================================
Created by: William Lam
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 = [pscustomobject] @{
Product = $results.product;
Type = $results.type;
Version = $results.version;
Build = $results.build;
InstallTime = $results.install_time;
Uptime = $uptime
}
$summaryResult
}
Function Get-VAMIHealth {
<#
.NOTES
===========================================================================
Created by: William Lam
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 = [pscustomobject] @{
HealthOverall = $healthOverall;
HealthLastCheck = $healthLastCheck;
HealthCPU = $healthCPU;
HealthMem = $healthMem;
HealthSwap = $healthSwap;
HealthStorage = $healthStorage;
HealthVCDB = $healthVCDB;
HealthSoftware = $healthSoftwareUpdates
}
$healthResult
}
Function Get-VAMIAccess {
<#
.NOTES
===========================================================================
Created by: William Lam
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 = New-Object PSObject -Property @{
Console = $consoleAccess;
DCUI = $dcuiAccess;
BashShell = $shellAccess.enabled;
SSH = $sshAccess
}
$accessResult
}
Function Get-VAMITime {
<#
.NOTES
===========================================================================
Created by: William Lam
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()
$timeSync = (Get-CisService -Name 'com.vmware.appliance.techpreview.timesync').get()
$timeSyncMode = $timeSync.mode
$timeResult = [pscustomobject] @{
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
}
$timeResult
}
Function Get-VAMINetwork {
<#
.NOTES
===========================================================================
Created by: William Lam
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) {
$ipv4API = (Get-CisService -Name 'com.vmware.appliance.techpreview.networking.ipv4')
$spec = $ipv4API.Help.get.interfaces.CreateExample()
$spec+= $interface.name
$ipv4result = $ipv4API.get($spec)
$interfaceResult = [pscustomobject] @{
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
}
Function Get-VAMIDisks {
<#
.NOTES
===========================================================================
Created by: William Lam
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
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()
}
Function Get-VAMIStatsList {
<#
.NOTES
===========================================================================
Created by: William Lam
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
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
}
Function Get-VAMIService {
<#
.NOTES
===========================================================================
Created by: William Lam
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
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
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
}
}
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
}
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
}
}
}
}

View File

@@ -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
}
}

View File

@@ -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
}
}

View File

@@ -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
}
}

View File

@@ -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
}
}
}

View File

@@ -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
}
}

View File

@@ -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
}
}

View File

@@ -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

View File

@@ -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
}
}
}

26
Scripts/VSANVersion.ps1 Normal file
View File

@@ -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
}

6
Scripts/modules.sh Normal file
View File

@@ -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