diff --git a/CHANGELOG.md b/CHANGELOG.md index ea2af43..b8e1c6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ Chore: - Updated `PowerVCF` from v2.3.0 to v2.4.0. [GH-85](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/85) - Added `PowerValidatedSolutions` v2.8.0 as a module dependency. [GH-38](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/38) +- Updated `Write-PowerManagementLogMessage` to set colour for message types. This will allow for all references to use colour based on function. [GH-89](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/89) ## v1.4.0 diff --git a/SampleScripts/PowerManagement-ManagementDomain.ps1 b/SampleScripts/PowerManagement-ManagementDomain.ps1 index 493db6a..0c6a7c4 100644 --- a/SampleScripts/PowerManagement-ManagementDomain.ps1 +++ b/SampleScripts/PowerManagement-ManagementDomain.ps1 @@ -98,9 +98,9 @@ Function Debug-CatchWriterForPowerManagement { $lineNumber = $object.InvocationInfo.ScriptLineNumber $lineText = $object.InvocationInfo.Line.trim() $errorMessage = $object.Exception.Message - Write-PowerManagementLogMessage -message " ERROR at Script Line $lineNumber" -Colour Red - Write-PowerManagementLogMessage -message " Relevant Command: $lineText" -Colour Red - Write-PowerManagementLogMessage -message " ERROR Message: $errorMessage" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message " ERROR at Script Line $lineNumber" + Write-PowerManagementLogMessage -Type ERROR -Message " Relevant Command: $lineText" + Write-PowerManagementLogMessage -Type ERROR -Message " ERROR Message: $errorMessage" Write-Error -Message $errorMessage } @@ -118,32 +118,32 @@ Try { $defaultFile = "./ManagementStartupInput.json" $inputFile = $null if ($json) { - Write-PowerManagementLogMessage -Type INFO -Message "The input JSON file provided." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "The input JSON file provided." $inputFile = $json } elseif (Test-Path -Path $defaultFile -PathType Leaf) { - Write-PowerManagementLogMessage -Type INFO -Message "No path to JSON provided in the command line. Using the auto-created input file ManagementStartupInput.json in the current directory." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "No path to JSON provided in the command line. Using the auto-created input file ManagementStartupInput.json in the current directory." $inputFile = $defaultFile } if ([string]::IsNullOrEmpty($inputFile)) { - Write-PowerManagementLogMessage -Type WARNING -Message "JSON input file is not provided. Cannot proceed! Exiting! " -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "JSON input file is not provided. Cannot proceed! Exiting! " Exit } Write-Host ""; $proceed = Read-Host "The following JSON file $inputFile will be used for the operation, please confirm (Yes or No)[default:No]" if (-Not $proceed) { - Write-PowerManagementLogMessage -Type WARNING -Message "None of the options is selected. Default is 'No', hence stopping script execution." -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "None of the options is selected. Default is 'No', hence stopping script execution." Exit } else { if (($proceed -match "no") -or ($proceed -match "yes")) { if ($proceed -match "no") { - Write-PowerManagementLogMessage -Type WARNING -Message "Stopping script execution because the input is 'No'." -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "Stopping script execution because the input is 'No'." Exit } } else { - Write-PowerManagementLogMessage -Type WARNING -Message "Pass the right string, either 'Yes' or 'No'." -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "Pass the right string, either 'Yes' or 'No'." Exit } } @@ -164,9 +164,9 @@ Try { if ($PsBoundParameters.ContainsKey("shutdownCustomerVm")) { $str2 = $str2 + " -shutdownCustomerVm" } if ($PsBoundParameters.ContainsKey("genjson")) { $str2 = $str2 + " -genjson" } if ($json) { $str2 = $str2 + " -json $json" } - Write-PowerManagementLogMessage -Type INFO -Message "Script used: $str1" -Colour Yellow - Write-PowerManagementLogMessage -Type INFO -Message "Script syntax: $str2" -Colour Yellow - if (-Not $null -eq $customerVmMessage) { Write-PowerManagementLogMessage -Type INFO -Message $customerVmMessage -Colour Yellow } + Write-PowerManagementLogMessage -Type INFO -Message "Script used: $str1" + Write-PowerManagementLogMessage -Type INFO -Message "Script syntax: $str2" + if (-Not $null -eq $customerVmMessage) { Write-PowerManagementLogMessage -Type INFO -Message $customerVmMessage} } Catch { Debug-CatchWriterForPowerManagement -object $_ @@ -179,20 +179,20 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe # Check connection to SDDC Manager Write-PowerManagementLogMessage -Type INFO -Message "Attempting to connect to VMware Cloud Foundation to gather system details." if (!(Test-EndpointConnection -server $server -Port 443)) { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot communicate with SDDC Manager ($server). Check the FQDN or IP address or the power state of '$server'." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot communicate with SDDC Manager ($server). Check the FQDN or IP address or the power state of '$server'." Exit } $StatusMsg = Request-VCFToken -fqdn $server -username $user -password $pass -WarningAction SilentlyContinue -ErrorAction SilentlyContinue -WarningVariable WarnMsg -ErrorVariable ErrorMsg if ( $StatusMsg ) { Write-PowerManagementLogMessage -Type INFO -Message $StatusMsg } - if ( $WarnMsg ) { Write-PowerManagementLogMessage -Type WARNING -Message $WarnMsg -Colour Cyan } - if ( $ErrorMsg ) { Write-PowerManagementLogMessage -Type ERROR -Message $ErrorMsg -Colour Red } + if ( $WarnMsg ) { Write-PowerManagementLogMessage -Type WARNING -Message $WarnMsg} + if ( $ErrorMsg ) { Write-PowerManagementLogMessage -Type ERROR -Message $ErrorMsg} if ($accessToken) { - Write-PowerManagementLogMessage -Type INFO -Message "Connection to SDDC Manager has been validated successfully." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "Connection to SDDC Manager has been validated successfully." Write-PowerManagementLogMessage -Type INFO -Message "Gathering system details from the SDDC Manager inventory. It will take some time." $workloadDomain = Get-VCFWorkloadDomain | Where-Object { $_.type -eq "MANAGEMENT" } # Check if we have single cluster in the MGMT domain if ($workloadDomain.clusters.id.count -gt 1) { - Write-PowerManagementLogMessage -Type ERROR -Message "There are multiple clusters in Management domain. This script supports only a single cluster per domain. Exiting!" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "There are multiple clusters in Management domain. This script supports only a single cluster per domain. Exiting!" Exit } $cluster = Get-VCFCluster | Where-Object { $_.id -eq ($workloadDomain.clusters.id) } @@ -220,13 +220,13 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe } # Test if VC is reachable, if it is already stopped, we could not continue with the shutdown sequence in automatic way. if (-Not (Test-EndpointConnection -server $vcServer.fqdn -Port 443) ) { - Write-PowerManagementLogMessage -Type WARNING -Message "Could not connect to $($vcServer.fqdn)! The script could not continue without a connection to the management vCenter Server. " -Colour Cyan - Write-PowerManagementLogMessage -Type ERROR -Message "Please check the current state and resolve the issue or continue with the shutdown operation by following the documentation of VMware Cloud Foundation. Exiting!" -Colour Red + Write-PowerManagementLogMessage -Type WARNING -Message "Could not connect to $($vcServer.fqdn)! The script could not continue without a connection to the management vCenter Server. " + Write-PowerManagementLogMessage -Type ERROR -Message "Please check the current state and resolve the issue or continue with the shutdown operation by following the documentation of VMware Cloud Foundation. Exiting!" Exit } $status = Get-TanzuEnabledClusterStatus -server $vcServer.fqdn -user $vcUser -pass $vcPass -cluster $cluster.name if ($status -eq $True) { - Write-PowerManagementLogMessage -Type ERROR -Message "Currently we are not supporting VMware Tanzu enabled domains. Please try on other workload domains." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Currently we are not supporting VMware Tanzu enabled domains. Please try on other workload domains." Exit } if ($vcPass) { @@ -309,7 +309,7 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe } } if ($statusOfNsxtClusterVMs -ne 'running') { - Write-PowerManagementLogMessage -Type WARNING -Message "NSX Manager VMs have been stopped. NSX Edge VMs will not be handled automatically." -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "NSX Manager VMs have been stopped. NSX Edge VMs will not be handled automatically." } else { Try { @@ -319,7 +319,7 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe Write-PowerManagementLogMessage -Type INFO -Message "The NSX Edge VMs are $edgenodesstring." } catch { - Write-PowerManagementLogMessage -Type ERROR -Message "Something went wrong! Cannot fetch NSX Edge nodes information from NSX Manager '$nsxtMgrfqdn'. Exiting!" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Something went wrong! Cannot fetch NSX Edge nodes information from NSX Manager '$nsxtMgrfqdn'. Exiting!" } } @@ -376,20 +376,20 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe if ($genjson) { if (Test-Path -Path "ManagementStartupInput.json" -PathType Leaf) { $location = Get-Location - Write-PowerManagementLogMessage -Type INFO -Message "#############################################################" -Colour Green - Write-PowerManagementLogMessage -Type INFO -Message "JSON generation is successful!" -Colour Green - Write-PowerManagementLogMessage -Type INFO -Message "ManagementStartupInput.json is created in the $location path." -Colour Green - Write-PowerManagementLogMessage -Type INFO -Message "#############################################################" -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "#############################################################" + Write-PowerManagementLogMessage -Type INFO -Message "JSON generation is successful!" + Write-PowerManagementLogMessage -Type INFO -Message "ManagementStartupInput.json is created in the $location path." + Write-PowerManagementLogMessage -Type INFO -Message "#############################################################" Exit } else { - Write-PowerManagementLogMessage -Type ERROR -Message "JSON file is not created. Check for permissions in the $location path" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "JSON file is not created. Check for permissions in the $location path" Exit } } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot obtain an access token from SDDC Manager ($server). Check your credentials." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot obtain an access token from SDDC Manager ($server). Check your credentials." Exit } @@ -400,13 +400,13 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe foreach ($esxiNode in $esxiWorkloadDomain) { $status = Get-SSHEnabledStatus -server $esxiNode.fqdn -user $esxiNode.username -pass $esxiNode.password if (-Not $status) { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot open an SSH connection to host $($esxiNode.fqdn). If SSH is not enabled, follow the steps in the documentation to enable it." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot open an SSH connection to host $($esxiNode.fqdn). If SSH is not enabled, follow the steps in the documentation to enable it." Exit } } } catch { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot open an SSH connection to host $($esxiNode.fqdn). If SSH is not enabled, follow the steps in the documentation to enable it." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot open an SSH connection to host $($esxiNode.fqdn). If SSH is not enabled, follow the steps in the documentation to enable it." } } else { #Lockdown mode - if enabled on any host, stop the script @@ -415,7 +415,7 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe foreach ($esxiNode in $esxiWorkloadDomain) { $HostConnectionState = Get-MaintenanceMode -server $esxiNode.fqdn -user $esxiNode.username -pass $esxiNode.password if ($HostConnectionState -eq "Maintenance") { - Write-PowerManagementLogMessage -Type ERROR -Message "$($esxiNode.fqdn) is in maintenance mode. Unable to shut down the cluster. Please take the host out of maintenance mode and run the script again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "$($esxiNode.fqdn) is in maintenance mode. Unable to shut down the cluster. Please take the host out of maintenance mode and run the script again." Exit } } @@ -432,10 +432,10 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe $customervms = $allvms | ? { $vcfvms -notcontains $_ } $vcfvms_string = $vcfvms -join "; " - Write-PowerManagementLogMessage -Type INFO -Message "Management virtual machines covered by the script: '$($vcfvms_string)' ." -Colour Cyan + Write-PowerManagementLogMessage -Type INFO -Message "Management virtual machines covered by the script: '$($vcfvms_string)' ." if ($customervms.count -ne 0) { $customervms_string = $customervms -join "; " - Write-PowerManagementLogMessage -Type INFO -Message "Virtual machines not covered by the script: '$($customervms_string)' . Those VMs will be stopped in a random order if the 'shutdownCustomerVm' flag is passed." -Colour Cyan + Write-PowerManagementLogMessage -Type INFO -Message "Virtual machines not covered by the script: '$($customervms_string)' . Those VMs will be stopped in a random order if the 'shutdownCustomerVm' flag is passed." } # Check if VMware Tools are running in the customer VMs - if not we could not stop them gracefully @@ -462,7 +462,7 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Unable to connect to vCenter Server '$($vcServer.fqdn)'. Command returned the following error: '$vcConnectError'." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Unable to connect to vCenter Server '$($vcServer.fqdn)'. Command returned the following error: '$vcConnectError'." } } # Disconnect from the VC @@ -471,8 +471,8 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe } if ($VMwareToolsNotRunningVMs.count -ne 0) { $noToolsVMs = $VMwareToolsNotRunningVMs -join "; " - Write-PowerManagementLogMessage -Type WARNING -Message "There are some non VCF maintained VMs where VMwareTools NotRunning, hence unable to shutdown these VMs:'$noToolsVMs'." -Colour cyan - Write-PowerManagementLogMessage -Type ERROR -Message "Unless these VMs are shutdown manually, we cannot proceed. Please shutdown manually and rerun the script." -Colour Red + Write-PowerManagementLogMessage -Type WARNING -Message "There are some non VCF maintained VMs where VMwareTools NotRunning, hence unable to shutdown these VMs:'$noToolsVMs'." + Write-PowerManagementLogMessage -Type ERROR -Message "Unless these VMs are shutdown manually, we cannot proceed. Please shutdown manually and rerun the script." Exit } } @@ -480,16 +480,16 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe if ($customervms.count -ne 0) { $customervms_string = $customervms -join "; " if ($PsBoundParameters.ContainsKey("shutdownCustomerVm")) { - Write-PowerManagementLogMessage -Type WARNING -Message "Some VMs are still in powered-on state. -shutdownCustomerVm is passed to the script." -Colour Cyan - Write-PowerManagementLogMessage -Type WARNING -Message "Hence shutting down VMs not managed by SDDC Manager to put the host in maintenance mode." -Colour Cyan - Write-PowerManagementLogMessage -Type WARNING -Message "The list of Non VCF management VMs: '$customervms_string'." -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "Some VMs are still in powered-on state. -shutdownCustomerVm is passed to the script." + Write-PowerManagementLogMessage -Type WARNING -Message "Hence shutting down VMs not managed by SDDC Manager to put the host in maintenance mode." + Write-PowerManagementLogMessage -Type WARNING -Message "The list of Non VCF management VMs: '$customervms_string'." # Stop Customer VMs with one call to VC: Stop-CloudComponent -server $vcServer.fqdn -user $vcUser -pass $vcPass -nodes $customervms -timeout 300 } else { - Write-PowerManagementLogMessage -Type WARNING -Message "Some VMs are still in powered-on state. -shutdownCustomerVm is not passed to the script." -Colour Cyan - Write-PowerManagementLogMessage -Type WARNING -Message "Hence not shutting down management VMs not managed by SDDC Manager: $($customervms_string) ." -Colour Cyan - Write-PowerManagementLogMessage -Type ERROR -Message "The script cannot proceed unless these VMs are shut down manually or the -shutdownCustomerVm option is present. Take the necessary action and run the script again." -Colour Red + Write-PowerManagementLogMessage -Type WARNING -Message "Some VMs are still in powered-on state. -shutdownCustomerVm is not passed to the script." + Write-PowerManagementLogMessage -Type WARNING -Message "Hence not shutting down management VMs not managed by SDDC Manager: $($customervms_string) ." + Write-PowerManagementLogMessage -Type ERROR -Message "The script cannot proceed unless these VMs are shut down manually or the -shutdownCustomerVm option is present. Take the necessary action and run the script again." Exit } } @@ -505,7 +505,7 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe if (($vcfVcenterDetails = Get-vCenterServerDetail -server $server -user $user -pass $pass -domain $domain.name)) { if (Test-vSphereConnection -server $($vcfVcenterDetails.fqdn)) { if (Test-vSphereAuthentication -server $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass) { - Write-PowerManagementLogMessage -Type INFO -Message "Stopping the VMware Aria Operations for Logs nodes..." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "Stopping the VMware Aria Operations for Logs nodes..." Stop-CloudComponent -server $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass -nodes $vmlist -timeout 600 } } @@ -538,17 +538,17 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe $vmName = $vm.Name $powerState = $vm.PowerState if ($powerState -eq "PoweredOn") { - Write-PowerManagementLogMessage -Type Error -Message "VM Name: $vmName, Power State: $powerState, Please power off the virtual machines connected to NSX Segments before you shutdown an NSX Edge Cluster" -Colour Red + Write-PowerManagementLogMessage -Type Error -Message "VM Name: $vmName, Power State: $powerState, Please power off the virtual machines connected to NSX Segments before you shutdown an NSX Edge Cluster" $stopExecuted = $true } if (-not $stopExecuted) { - Write-PowerManagementLogMessage -Type INFO -Message "Stopping the NSX Edge nodes..." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "Stopping the NSX Edge nodes..." Stop-CloudComponent -server $server -user $user -pass $pass -nodes $nsxtEdgeNodes -timeout 600 $stopExecuted = $true } } } else { - Write-PowerManagementLogMessage -Type WARNING -Message "No NSX Edge nodes present. Skipping shutdown..." -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "No NSX Edge nodes present. Skipping shutdown..." } } } @@ -560,25 +560,25 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe } #Stop NSX Manager nodes - Write-PowerManagementLogMessage -Type INFO -Message "Stopping the NSX Manager nodes..." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "Stopping the NSX Manager nodes..." Stop-CloudComponent -server $vcServer.fqdn -user $vcUser -pass $vcPass -nodes $nsxtNodes -timeout 600 #Check the vSAN health before SDDC manager is stopped if ( (Test-VsanHealth -cluster $cluster.name -server $vcServer.fqdn -user $vcUser -pass $vcPass) -eq 0) { - #Write-PowerManagementLogMessage -Type INFO -Message "vSAN cluster health is good." -Colour Green + #Write-PowerManagementLogMessage -Type INFO -Message "vSAN cluster health is good." } else { - Write-PowerManagementLogMessage -Type WARNING -Message "The vSAN cluster isn't in a healthy state. Check the vSAN cluster status in vCenter Server '$($vcServer.fqdn)'. After you resolve the vSAN health issues, run the script again." -Colour Cyan - Write-PowerManagementLogMessage -Type WARNING -Message "If the script has reached ESXi vSAN shutdown previously, this error is expected. Continue the shutdown workflow by following the documentation of VMware Cloud Foundation. " -Colour Cyan - Write-PowerManagementLogMessage -Type ERROR -Message "The vSAN cluster isn't in a healthy state. Check the messages above for a solution." -Colour Red + Write-PowerManagementLogMessage -Type WARNING -Message "The vSAN cluster isn't in a healthy state. Check the vSAN cluster status in vCenter Server '$($vcServer.fqdn)'. After you resolve the vSAN health issues, run the script again." + Write-PowerManagementLogMessage -Type WARNING -Message "If the script has reached ESXi vSAN shutdown previously, this error is expected. Continue the shutdown workflow by following the documentation of VMware Cloud Foundation. " + Write-PowerManagementLogMessage -Type ERROR -Message "The vSAN cluster isn't in a healthy state. Check the messages above for a solution." Exit } if ((Test-VsanObjectResync -cluster $cluster.name -server $vcServer.fqdn -user $vcUser -pass $vcPass) -eq 0) { - #Write-PowerManagementLogMessage -Type INFO -Message "vSAN object resynchronization is successful." -Colour Green + #Write-PowerManagementLogMessage -Type INFO -Message "vSAN object resynchronization is successful." } else { - Write-PowerManagementLogMessage -Type ERROR -Message "vSAN object resynchronization is running. Stopping the script... Wait until the vSAN object resynchronization is completed and run the script again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "vSAN object resynchronization is running. Stopping the script... Wait until the vSAN object resynchronization is completed and run the script again." Exit } @@ -590,7 +590,7 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe Set-Retreatmode -server $vcServer.fqdn -user $vcUser -pass $vcPass -cluster $cluster.name -mode enable # Waiting for vCLS VMs to be stopped for ($retries*10) seconds - Write-PowerManagementLogMessage -Type INFO -Message "vCLS retreat mode has been set. vCLS shutdown will take time. Please wait!" -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "vCLS retreat mode has been set. vCLS shutdown will take time. Please wait!" $counter = 0 $retries = 10 $sleepTime = 30 @@ -605,7 +605,7 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe } } if ($counter -eq $retries) { - Write-PowerManagementLogMessage -Type ERROR -Message "The vCLS VMs were not shut down within the expected time. Stopping the script execution... " -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "The vCLS VMs were not shut down within the expected time. Stopping the script execution... " Exit } @@ -613,7 +613,7 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe if ([float]$vcfVersion -le [float]4.5) { # Stop vSphere HA to avoid "orphaned" VMs during vSAN shutdown if (!$(Set-VsphereHA -server $vcServer.fqdn -user $vcUser -pass $vcPass -cluster $cluster.name -disableHA)) { - Write-PowerManagementLogMessage -Type ERROR -Message "Could not disable vSphere High Availability for cluster '$cluster'. Exiting!" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Could not disable vSphere High Availability for cluster '$cluster'. Exiting!" } # Set DRS Automation Level to Manual in the Management Domain @@ -624,26 +624,26 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe $RemoteVMs = @() $RemoteVMs = Get-poweronVMsOnRemoteDS -server $vcServer.fqdn -user $vcUser -pass $vcPass -clustertocheck $cluster.name if($RemoteVMs.count -eq 0) { - Write-PowerManagementLogMessage -Type INFO -Message "All remote VMs are powered off." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "All remote VMs are powered off." } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Some remote VMs are still powered-on : $($RemoteVMs.Name). Cannot proceed until the powered-on VMs are shut down. Check your environment." -Colour RED + Write-PowerManagementLogMessage -Type ERROR -Message "Some remote VMs are still powered-on : $($RemoteVMs.Name). Cannot proceed until the powered-on VMs are shut down. Check your environment." } #Testing VSAN health after SDDC manager is stopped if ( (Test-VsanHealth -cluster $cluster.name -server $vcServer.fqdn -user $vcUser -pass $vcPass) -eq 0) { - Write-PowerManagementLogMessage -Type INFO -Message "vSAN cluster health is good." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "vSAN cluster health is good." } else { - Write-PowerManagementLogMessage -Type WARNING -Message "The vSAN cluster isn't in a healthy state. Check the vSAN status in vCenter Server '$($vcServer.fqdn)'. After you resolve the vSAN issues, run the script again." -Colour Cyan - Write-PowerManagementLogMessage -Type WARNING -Message "If the script has reached ESXi vSAN shutdown previously, this error is expected. Continue by following the documentation of VMware Cloud Foundation. " -Colour Cyan - Write-PowerManagementLogMessage -Type ERROR -Message "The vSAN cluster isn't in a healthy state. Check the messages above for a solution." -Colour Red + Write-PowerManagementLogMessage -Type WARNING -Message "The vSAN cluster isn't in a healthy state. Check the vSAN status in vCenter Server '$($vcServer.fqdn)'. After you resolve the vSAN issues, run the script again." + Write-PowerManagementLogMessage -Type WARNING -Message "If the script has reached ESXi vSAN shutdown previously, this error is expected. Continue by following the documentation of VMware Cloud Foundation. " + Write-PowerManagementLogMessage -Type ERROR -Message "The vSAN cluster isn't in a healthy state. Check the messages above for a solution." Exit } if ((Test-VsanObjectResync -cluster $cluster.name -server $vcServer.fqdn -user $vcUser -pass $vcPass) -eq 0) { - Write-PowerManagementLogMessage -Type INFO -Message "VSAN object resynchronization is successful." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "VSAN object resynchronization is successful." } else { - Write-PowerManagementLogMessage -Type ERROR -Message "vSAN object resynchronization is running. Stopping the script. Wait until the vSAN object resynchronization is completed and run the script again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "vSAN object resynchronization is running. Stopping the script. Wait until the vSAN object resynchronization is completed and run the script again." Exit } @@ -651,21 +651,21 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe # Verify that there is only one VM running (vCenter Server) on the ESXis, then shutdown vCenter Server. $runningVMs = Get-VMsWithPowerStatus -powerstate "poweredon" -server $vcServer.fqdn -user $vcUser -pass $vcPass -silence if ($runningVMs.count -gt 1 ) { - Write-PowerManagementLogMessage -Type WARNING -Message "Some VMs are still in powered-on state." -Colour Cyan - Write-PowerManagementLogMessage -Type WARNING -Message "Cannot proceed until the powered-on VMs are shut down. Shut them down them manually and continue with the shutdown operation by following documentation of VMware Cloud Foundation." -Colour Cyan - Write-PowerManagementLogMessage -Type ERROR -Message "There are running VMs in environment: $($runningVMs). Exiting! " -Colour Red + Write-PowerManagementLogMessage -Type WARNING -Message "Some VMs are still in powered-on state." + Write-PowerManagementLogMessage -Type WARNING -Message "Cannot proceed until the powered-on VMs are shut down. Shut them down them manually and continue with the shutdown operation by following documentation of VMware Cloud Foundation." + Write-PowerManagementLogMessage -Type ERROR -Message "There are running VMs in environment: $($runningVMs). Exiting! " } else { Write-PowerManagementLogMessage -Type INFO -Message "There are no VMs in powered-on state. Hence, shutting down vCenter Server..." # Shutdown vCenter Server Stop-CloudComponent -server $vcHost -user $vcHostUser -pass $vcHostPass -pattern $vcServer.fqdn.Split(".")[0] -timeout 600 if (Get-VMRunningStatus -server $vcHost -user $vcHostUser -pass $vcHostPass -pattern $vcServer.fqdn.Split(".")[0] -Status "Running") { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot stop vCenter Server on the host. Exiting!" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot stop vCenter Server on the host. Exiting!" } } } # Verify that there are no running VMs on the ESXis and shutdown the vSAN cluster. - Write-PowerManagementLogMessage -Type INFO -Message "Checking that there are no running VMs on the ESXi hosts before stopping vSAN." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "Checking that there are no running VMs on the ESXi hosts before stopping vSAN." $runningVMsPresent = $False $runningVMs = @() $runningVclsVMs = @() @@ -679,15 +679,15 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe $runningVMs = $runningAllVMs | ? { $runningVclsVMs -notcontains $_ } } if ($runningVMs.count) { - Write-PowerManagementLogMessage -Type WARNING -Message "Some VMs are still in powered-on state." -Colour Cyan - Write-PowerManagementLogMessage -Type WARNING -Message "Cannot proceed until the powered-on VMs are shut down. Shut down them down manually and run the script again." -Colour Cyan - Write-PowerManagementLogMessage -Type WARNING -Message "ESXi with VMs running: $($esxiNode.fqdn) VMs are:$($runningVMs) " -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "Some VMs are still in powered-on state." + Write-PowerManagementLogMessage -Type WARNING -Message "Cannot proceed until the powered-on VMs are shut down. Shut down them down manually and run the script again." + Write-PowerManagementLogMessage -Type WARNING -Message "ESXi with VMs running: $($esxiNode.fqdn) VMs are:$($runningVMs) " $runningVMsPresent = $True } } # Verify that there are no running VMs on the ESXis and shutdown the vSAN cluster. if ($runningVMsPresent) { - Write-PowerManagementLogMessage -Type ERROR -Message "Some VMs on the ESXi hosts are still in powered-on state. Check the console log, stop the VMs and continue the shutdown operation manually." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Some VMs on the ESXi hosts are still in powered-on state. Check the console log, stop the VMs and continue the shutdown operation manually." } # Actual vSAN and ESXi shutdown happens here - once we are sure that there are no VMs running on hosts else { @@ -708,8 +708,8 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe Set-MaintenanceMode -server $esxiNode.fqdn -user $esxiNode.username -pass $esxiNode.password -state ENABLE } # End of shutdown - Write-PowerManagementLogMessage -Type INFO -Message "End of the shutdown sequence!" -Colour Cyan - Write-PowerManagementLogMessage -Type INFO -Message "Shut down the ESXi hosts!" -Colour Cyan + Write-PowerManagementLogMessage -Type INFO -Message "End of the shutdown sequence!" + Write-PowerManagementLogMessage -Type INFO -Message "Shut down the ESXi hosts!" } else { # vSAN shutdown wizard automation. @@ -727,15 +727,15 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe #Verify if all ESXi hosts are down in here to conclude End of Shutdown sequence foreach ($esxiNode in $esxiWorkloadDomain) { if (Test-EndpointConnection -server $esxiNode.fqdn -Port 443) { - Write-PowerManagementLogMessage -Type WARNING -Message "Some hosts are still up. Sleeping for 60 seconds before next check..." -Colour cyan + Write-PowerManagementLogMessage -Type WARNING -Message "Some hosts are still up. Sleeping for 60 seconds before next check..." break } else { $successcount++ } } if ($successcount -eq $esxiWorkloadDomain.count) { - Write-PowerManagementLogMessage -Type INFO -Message "All hosts have been shut down successfully!" -Colour Green - Write-PowerManagementLogMessage -Type INFO -Message "End of the shutdown sequence!" -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "All hosts have been shut down successfully!" + Write-PowerManagementLogMessage -Type INFO -Message "End of the shutdown sequence!" Exit } else { Start-Sleep -s $sleepTime @@ -839,25 +839,25 @@ if ($PsBoundParameters.ContainsKey("startup")) { Write-Host ""; $proceed = Read-Host "Please start all the ESXi host belonging to the cluster '$($cluster.name)' and wait for the host console to come up. Once done, please enter yes." if (-Not $proceed) { - Write-PowerManagementLogMessage -Type WARNING -Message "None of the options is selected. Default is 'No', hence, stopping script execution..." -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "None of the options is selected. Default is 'No', hence, stopping script execution..." Exit } else { if (($proceed -match "no") -or ($proceed -match "yes")) { if ($proceed -match "no") { - Write-PowerManagementLogMessage -Type WARNING -Message "Stopping script execution because the input is 'No'..." -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "Stopping script execution because the input is 'No'..." Exit } } else { - Write-PowerManagementLogMessage -Type WARNING -Message "Pass the right string - either 'Yes' or 'No'." -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "Pass the right string - either 'Yes' or 'No'." Exit } } foreach ($esxiNode in $esxiWorkloadDomain) { if (!(Test-EndpointConnection -server $esxiNode.fqdn -Port 443)) { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot communicate with host $($esxiNode.fqdn). Check the FQDN or IP address, or the power state of '$($esxiNode.fqdn)'." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot communicate with host $($esxiNode.fqdn). Check the FQDN or IP address, or the power state of '$($esxiNode.fqdn)'." Exit } } @@ -867,13 +867,13 @@ if ($PsBoundParameters.ContainsKey("startup")) { foreach ($esxiNode in $esxiWorkloadDomain) { $status = Get-SSHEnabledStatus -server $esxiNode.fqdn -user $esxiNode.username -pass $esxiNode.password if (-Not $status) { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot open an SSH connection to host $($esxiNode.fqdn). If SSH is not enabled, follow the steps in the documentation to enable it." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot open an SSH connection to host $($esxiNode.fqdn). If SSH is not enabled, follow the steps in the documentation to enable it." Exit } } } catch { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot open an SSH connection to host $($esxiNode.fqdn). If SSH is not enabled, follow the steps in the documentation to enable it." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot open an SSH connection to host $($esxiNode.fqdn). If SSH is not enabled, follow the steps in the documentation to enable it." } # Take hosts out of maintenance mode @@ -895,7 +895,7 @@ if ($PsBoundParameters.ContainsKey("startup")) { Invoke-EsxCommand -server $esxiNode.fqdn -user $esxiNode.username -pass $esxiNode.password -expected "Value of IgnoreClusterMemberListUpdates is 0" -cmd "esxcfg-advcfg -s 0 /VSAN/IgnoreClusterMemberListUpdates" } - Write-PowerManagementLogMessage -Type INFO -Message "Checking vSAN status of the ESXi hosts." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "Checking vSAN status of the ESXi hosts." foreach ($esxiNode in $esxiWorkloadDomain) { Invoke-EsxCommand -server $esxiNode.fqdn -user $esxiNode.username -pass $esxiNode.password -expected "Local Node Health State: HEALTHY" -cmd "esxcli vsan cluster get" } @@ -905,15 +905,15 @@ if ($PsBoundParameters.ContainsKey("startup")) { Start-Sleep -s 5 if (-Not (Get-VMRunningStatus -server $vcHost -user $vcHostUser -pass $vcHostPass -pattern $vcServer.fqdn.Split(".")[0] -Status "Running")) { - Write-PowerManagementLogMessage -Type Warning -Message "Cannot start vCenter Server on the host. Check if vCenter Server is located on host $vcHost. " -Colour Red - Write-PowerManagementLogMessage -Type Warning -Message "Start vCenter Server manually and run the script again." -Colour Red - Write-PowerManagementLogMessage -Type ERROR -Message "Could not start vCenter Server on host $vcHost. Check the console log for more details." -Colour Red + Write-PowerManagementLogMessage -Type Warning -Message "Cannot start vCenter Server on the host. Check if vCenter Server is located on host $vcHost. " + Write-PowerManagementLogMessage -Type Warning -Message "Start vCenter Server manually and run the script again." + Write-PowerManagementLogMessage -Type ERROR -Message "Could not start vCenter Server on host $vcHost. Check the console log for more details." Exit } } } else { - Write-PowerManagementLogMessage -Type INFO -Message "vCenter Server '$($vcServer.fqdn)' is running. Skipping vSAN startup!" -Colour Cyan + Write-PowerManagementLogMessage -Type INFO -Message "vCenter Server '$($vcServer.fqdn)' is running. Skipping vSAN startup!" } # Wait till VC is started, continue if it is already up and running @@ -945,7 +945,7 @@ if ($PsBoundParameters.ContainsKey("startup")) { } # Check if VC have been started in the above time period if (!$retries) { - Write-PowerManagementLogMessage -Type ERROR -Message "Timeout while waiting vCenter Server to start. Exiting!" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Timeout while waiting vCenter Server to start. Exiting!" } #Restart Cluster Via Wizard @@ -957,12 +957,12 @@ if ($PsBoundParameters.ContainsKey("startup")) { } # Check vSAN Status if ( (Test-VsanHealth -cluster $cluster.name -server $vcServer.fqdn -user $vcUser -pass $vcPass) -ne 0) { - Write-PowerManagementLogMessage -Type ERROR -Message "vSAN cluster health is bad. Check your environment and run the script again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "vSAN cluster health is bad. Check your environment and run the script again." Exit } # Check vSAN Status if ( (Test-VsanObjectResync -cluster $cluster.name -server $vcServer.fqdn -user $vcUser -pass $vcPass) -ne 0) { - Write-PowerManagementLogMessage -Type ERROR -Message "vSAN object resynchronization is in progress. Check your environment and run the script again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "vSAN object resynchronization is in progress. Check your environment and run the script again." Exit } @@ -970,12 +970,12 @@ if ($PsBoundParameters.ContainsKey("startup")) { if ([float]$vcfVersion -lt [float]4.5) { # Start vSphere HA if (!$(Set-VsphereHA -server $vcServer.fqdn -user $vcUser -pass $vcPass -cluster $cluster.name -enableHA)) { - Write-PowerManagementLogMessage -Type ERROR -Message "Could not enable vSphere High Availability for cluster '$cluster'." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Could not enable vSphere High Availability for cluster '$cluster'." } # Restore the DRS Automation Level to the mode backed up for Management Domain Cluster during shutdown if ([string]::IsNullOrEmpty($DrsAutomationLevel)) { - Write-PowerManagementLogMessage -Type ERROR -Message "The DrsAutomationLevel value in the JSON file is empty. Exiting!" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "The DrsAutomationLevel value in the JSON file is empty. Exiting!" Exit } else { @@ -1001,7 +1001,7 @@ if ($PsBoundParameters.ContainsKey("startup")) { } } if ($counter -eq $retries) { - Write-PowerManagementLogMessage -Type ERROR -Message "The vCLS virtual machines did not start within the expected time. Stopping script execution..." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "The vCLS virtual machines did not start within the expected time. Stopping script execution..." Exit } @@ -1011,7 +1011,7 @@ if ($PsBoundParameters.ContainsKey("startup")) { # Startup the NSX Manager Nodes in the Management Workload Domain Start-CloudComponent -server $vcServer.fqdn -user $vcUser -pass $vcPass -nodes $nsxtNodes -timeout 600 if (!(Wait-ForStableNsxtClusterStatus -server $nsxtMgrfqdn -user $nsxMgrVIP.adminUser -pass $nsxMgrVIP.adminPassword)) { - Write-PowerManagementLogMessage -Type ERROR -Message "The NSX Manager cluster is not in 'STABLE' state. Exiting!" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "The NSX Manager cluster is not in 'STABLE' state. Exiting!" Exit } @@ -1020,26 +1020,26 @@ if ($PsBoundParameters.ContainsKey("startup")) { Start-CloudComponent -server $vcServer.fqdn -user $vcUser -pass $vcPass -nodes $nsxtEdgeNodes -timeout 600 } else { - Write-PowerManagementLogMessage -Type WARNING -Message "No NSX Edge nodes present. Skipping startup..." -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "No NSX Edge nodes present. Skipping startup..." } # End of startup - Write-PowerManagementLogMessage -Type INFO -Message "##################################################################################" -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "##################################################################################" if ([float]$vcfVersion -lt [float]4.5) { - Write-PowerManagementLogMessage -Type INFO -Message "vSphere vSphere High Availability has been enabled by the script. Please disable it according to your environment's design." -Colour Cyan + Write-PowerManagementLogMessage -Type INFO -Message "vSphere vSphere High Availability has been enabled by the script. Please disable it according to your environment's design." } - Write-PowerManagementLogMessage -Type INFO -Message "Check your environment and start any additional virtual machines that you host in the management domain." -Colour Green - Write-PowerManagementLogMessage -Type INFO -Message "Use the following command to automatically start VMs" -Colour Yellow - Write-PowerManagementLogMessage -Type INFO -Message "Start-CloudComponent -server $($vcServer.fqdn) -user $vcUser -pass $vcPass -nodes -timeout 600" -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Check your environment and start any additional virtual machines that you host in the management domain." + Write-PowerManagementLogMessage -Type INFO -Message "Use the following command to automatically start VMs" + Write-PowerManagementLogMessage -Type INFO -Message "Start-CloudComponent -server $($vcServer.fqdn) -user $vcUser -pass $vcPass -nodes -timeout 600" if ([float]$vcfVersion -lt [float]4.5) { - Write-PowerManagementLogMessage -Type INFO -Message "If you have enabled SSH for the ESXi hosts in management domain, disable it at this point." -Colour Cyan + Write-PowerManagementLogMessage -Type INFO -Message "If you have enabled SSH for the ESXi hosts in management domain, disable it at this point." } if ([float]$vcfVersion -gt [float]4.4) { - Write-PowerManagementLogMessage -Type INFO -Message "If you have disabled lockdown mode for the ESXi hosts in management domain, enable it back at this point." -Colour Cyan + Write-PowerManagementLogMessage -Type INFO -Message "If you have disabled lockdown mode for the ESXi hosts in management domain, enable it back at this point." } - Write-PowerManagementLogMessage -Type INFO -Message "##################################################################################" -Colour Green - Write-PowerManagementLogMessage -Type INFO -Message "End of the startup sequence!" -Colour Green - Write-PowerManagementLogMessage -Type INFO -Message "##################################################################################" -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "##################################################################################" + Write-PowerManagementLogMessage -Type INFO -Message "End of the startup sequence!" + Write-PowerManagementLogMessage -Type INFO -Message "##################################################################################" } Catch { Debug-CatchWriterForPowerManagement -object $_ diff --git a/SampleScripts/PowerManagement-WorkloadDomain.ps1 b/SampleScripts/PowerManagement-WorkloadDomain.ps1 index 2b3d076..95f63de 100644 --- a/SampleScripts/PowerManagement-WorkloadDomain.ps1 +++ b/SampleScripts/PowerManagement-WorkloadDomain.ps1 @@ -92,9 +92,9 @@ Function Debug-CatchWriterForPowerManagement { $lineNumber = $object.InvocationInfo.ScriptLineNumber $lineText = $object.InvocationInfo.Line.trim() $errorMessage = $object.Exception.Message - Write-PowerManagementLogMessage -message " ERROR at Script Line $lineNumber" -Colour Red - Write-PowerManagementLogMessage -message " Relevant Command: $lineText" -Colour Red - Write-PowerManagementLogMessage -message " ERROR Message: $errorMessage" -Colour Red + Write-PowerManagementLogMessage -message " ERROR at Script Line $lineNumber" + Write-PowerManagementLogMessage -message " Relevant Command: $lineText" + Write-PowerManagementLogMessage -message " ERROR Message: $errorMessage" Write-Error -Message $errorMessage } @@ -120,22 +120,22 @@ Try { if ($PsBoundParameters.ContainsKey("startup")) { $str2 = $str2 + " -startup" } if ($PsBoundParameters.ContainsKey("shutdown")) { $str2 = $str2 + " -shutdown" } if ($PsBoundParameters.ContainsKey("shutdownCustomerVm")) { $str2 = $str2 + " -shutdownCustomerVm" } - Write-PowerManagementLogMessage -Type INFO -Message "Script used: $str1" -Colour Yellow - Write-PowerManagementLogMessage -Type INFO -Message "Script syntax: $str2" -Colour Yellow - Write-PowerManagementLogMessage -Type INFO -Message "Setting up the log file to path $logfile" -Colour Yellow - if (-Not $null -eq $customerVmMessage) { Write-PowerManagementLogMessage -Type INFO -Message $customerVmMessage -Colour Yellow } + Write-PowerManagementLogMessage -Type INFO -Message "Script used: $str1" + Write-PowerManagementLogMessage -Type INFO -Message "Script syntax: $str2" + Write-PowerManagementLogMessage -Type INFO -Message "Setting up the log file to path $logfile" + if (-Not $null -eq $customerVmMessage) { Write-PowerManagementLogMessage -Type INFO -Message $customerVmMessage } if (!(Test-EndpointConnection -server $server -Port 443)) { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot communicate with SDDC Manager ($server). Check the FQDN or IP address or power state of the '$server'." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot communicate with SDDC Manager ($server). Check the FQDN or IP address or power state of the '$server'." Exit } else { $StatusMsg = Request-VCFToken -fqdn $server -username $user -password $pass -WarningAction SilentlyContinue -ErrorAction SilentlyContinue -WarningVariable WarnMsg -ErrorVariable ErrorMsg if ( $StatusMsg ) { Write-PowerManagementLogMessage -Type INFO -Message $StatusMsg } - if ( $WarnMsg ) { Write-PowerManagementLogMessage -Type WARNING -Message $WarnMsg -Colour Cyan } - if ( $ErrorMsg ) { Write-PowerManagementLogMessage -Type ERROR -Message $ErrorMsg -Colour Red } + if ( $WarnMsg ) { Write-PowerManagementLogMessage -Type WARNING -Message $WarnMsg } + if ( $ErrorMsg ) { Write-PowerManagementLogMessage -Type ERROR -Message $ErrorMsg } if ($accessToken) { - Write-PowerManagementLogMessage -Type INFO -Message "Connection to SDDC Manager has been validated successfully."-Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "Connection to SDDC Manager has been validated successfully." } } } @@ -148,7 +148,7 @@ Try { $original_flow = $false Write-PowerManagementLogMessage -Type INFO -Message "Attempting to connect to VMware Cloud Foundation to gather system details..." $StatusMsg = Request-VCFToken -fqdn $server -username $user -password $pass -WarningAction SilentlyContinue -ErrorAction SilentlyContinue -WarningVariable WarnMsg -ErrorVariable ErrorMsg - if ($StatusMsg) { Write-PowerManagementLogMessage -Type INFO -Message $StatusMsg } if ($WarnMsg) { Write-PowerManagementLogMessage -Type WARNING -Message $WarnMsg -Colour Magenta } if ($ErrorMsg) { Write-PowerManagementLogMessage -Type ERROR -Message $ErrorMsg -Colour Red } + if ($StatusMsg) { Write-PowerManagementLogMessage -Type INFO -Message $StatusMsg } if ($WarnMsg) { Write-PowerManagementLogMessage -Type WARNING -Message $WarnMsg } if ($ErrorMsg) { Write-PowerManagementLogMessage -Type ERROR -Message $ErrorMsg } if ($accessToken) { Write-PowerManagementLogMessage -Type INFO -Message "Gathering system details from the SDDC Manager inventory... It will take some time." @@ -158,7 +158,7 @@ Try { $allWld = Get-VCFWorkloadDomain | Where-Object { ($_.Type -ne "MANAGEMENT") } $allWldVCs = $allWld.vcenters.fqdn if ([string]::IsNullOrEmpty($workloadDomain)) { - Write-PowerManagementLogMessage -Type ERROR -Message "Domain $sddcDomain doesn't exist. Check your environment and try again. " -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Domain $sddcDomain doesn't exist. Check your environment and try again. " Exit } # Check if there are multiple clusters in the WLD @@ -203,16 +203,16 @@ Try { } $ClusterDetails = $userClusterDetails if (($userClusterDetails.count -eq $sddcClusterDetails.count) -and (((Compare-Object $userClusterDetails $sddcClusterDetails -IncludeEqual | Where-Object -FilterScript {$_.SideIndicator -eq '=='}).InputObject).count -eq $sddcClusterDetails.count)) { - Write-PowerManagementLogMessage -Type INFO -Message "All cluster-related information is correct." -colour green + Write-PowerManagementLogMessage -Type INFO -Message "All cluster-related information is correct." $allClusterShutdown = $true } if(((Compare-Object $sddcClusterarray $userClusterarray -IncludeEqual | Where-Object -FilterScript {$_.SideIndicator -eq '=>'}).InputObject).count){ $wrongClusterNames = (Compare-Object $sddcClusterarray $userClusterarray -IncludeEqual | Where-Object -FilterScript {$_.SideIndicator -eq '=>'}).InputObject - Write-PowerManagementLogMessage -Type WARNING -Message "A wrong cluster name has been passed." -Colour Cyan - Write-PowerManagementLogMessage -Type WARNING -Message "The known clusters, part of this workload domain are:$($sddcClusterDetails.name)" -Colour Cyan - Write-PowerManagementLogMessage -Type WARNING -Message "The cluster names passed are: $userClusterarray" -Colour Cyan - Write-PowerManagementLogMessage -Type WARNING -Message "Clusters not matching the SDDC Manager database: $wrongClusterNames" -Colour Cyan - Write-PowerManagementLogMessage -Type ERROR -Message "Please cross check and run the script again. Exiting!" -Colour Red + Write-PowerManagementLogMessage -Type WARNING -Message "A wrong cluster name has been passed." + Write-PowerManagementLogMessage -Type WARNING -Message "The known clusters, part of this workload domain are:$($sddcClusterDetails.name)" + Write-PowerManagementLogMessage -Type WARNING -Message "The cluster names passed are: $userClusterarray" + Write-PowerManagementLogMessage -Type WARNING -Message "Clusters not matching the SDDC Manager database: $wrongClusterNames" + Write-PowerManagementLogMessage -Type ERROR -Message "Please cross check and run the script again. Exiting!" } Write-PowerManagementLogMessage -Type INFO -Message "All clusters to be taken care of: '$allClusterShutdown'" } else { @@ -271,7 +271,7 @@ Try { if ($vxrailVMObject) { $vxRailVmName = $vxrailVMObject.Name } else { - Write-PowerManagementLogMessage -Type ERROR -Message "VxRail($($vxRailCred.resource.resourceName)) Virtual Machine object cannot be located within VC Server ($($vcServer.fqdn))" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "VxRail($($vxRailCred.resource.resourceName)) Virtual Machine object cannot be located within VC Server ($($vcServer.fqdn))" } } } @@ -330,19 +330,19 @@ Try { } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$($vcServer.fqdn)' has failed. Check the console output for more details." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$($vcServer.fqdn)' has failed. Check the console output for more details." } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$($vcServer.fqdn)' has failed. Check your environment and try again" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$($vcServer.fqdn)' has failed. Check your environment and try again" } } } # We will get NSX-T details in the respective startup/shutdown sections below. } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to vCenter Server ($($vcServer.fqdn)). Check your credentials." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to vCenter Server ($($vcServer.fqdn)). Check your credentials." Exit } } @@ -386,7 +386,7 @@ Try { $nxtClusterEdgeNodes = @() if ($statusOfNsxtClusterVMs -ne 'running') { - Write-PowerManagementLogMessage -Type WARNING -Message "The NSX Manager VMs have been stopped. The NSX Edge VMs will not be handled in an automatic way." -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "The NSX Manager VMs have been stopped. The NSX Edge VMs will not be handled in an automatic way." } else { Try { @@ -396,7 +396,7 @@ Try { } } catch { - Write-PowerManagementLogMessage -Type ERROR -Message "Something went wrong! Unable to fetch NSX Edge node information from NSX Manager '$nsxtMgrfqdn'. Exiting!" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Something went wrong! Unable to fetch NSX Edge node information from NSX Manager '$nsxtMgrfqdn'. Exiting!" } } @@ -425,7 +425,7 @@ Try { } if ($ClusterStatusMapping[$cluster.name] -eq 'DOWN') { - Write-PowerManagementLogMessage -Type INFO -Message "Cluster '$($cluster.name)' is already stopped, hence proceeding with next cluster in the sequence" -Colour GREEN + Write-PowerManagementLogMessage -Type INFO -Message "Cluster '$($cluster.name)' is already stopped, hence proceeding with next cluster in the sequence" Continue } @@ -440,17 +440,17 @@ Try { foreach ($esxiNode in $esxiDetails) { $status = Get-SSHEnabledStatus -server $esxiNode.fqdn -user $esxiNode.username -pass $esxiNode.password if (-Not $status) { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot open an SSH connection to host $($esxiNode.fqdn). If SSH is not enabled, follow the steps in the documentation to enable it." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot open an SSH connection to host $($esxiNode.fqdn). If SSH is not enabled, follow the steps in the documentation to enable it." } } } catch { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot open an SSH connection to host $($esxiNode.fqdn), If SSH is not enabled, follow the steps in the documentation to enable it." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot open an SSH connection to host $($esxiNode.fqdn), If SSH is not enabled, follow the steps in the documentation to enable it." } } else { foreach ($esxiNode in $esxiDetails) { if (!(Test-EndpointConnection -server $esxiNode.fqdn -Port 443)) { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot communicate with the host $($esxiNode.fqdn). Check the FQDN or IP address, or the power state of '$($esxiNode.fqdn)'." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot communicate with the host $($esxiNode.fqdn). Check the FQDN or IP address, or the power state of '$($esxiNode.fqdn)'." Exit } } @@ -460,7 +460,7 @@ Try { # Check if Tanzu is enabled in WLD $status = Get-TanzuEnabledClusterStatus -server $vcServer.fqdn -user $vcUser -pass $vcPass -cluster $cluster.name if ($status -eq $True) { - Write-PowerManagementLogMessage -Type ERROR -Message "Currently workload domains with vSphere with Tanzu are not supported. Exiting." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Currently workload domains with vSphere with Tanzu are not supported. Exiting." } $clustervcfvms = @() @@ -488,10 +488,10 @@ Try { Write-PowerManagementLogMessage -Type INFO -Message "Trying to fetch information about all powered-on customer virtual machines for the specified vSphere cluster $($cluster.name)..." $clustercustomervms = $clusterallvms | ? { $vcfvms -notcontains $_ } $clustervcfvms_string = $clustervcfvms -join "; " - Write-PowerManagementLogMessage -Type INFO -Message "Management virtual machines covered by the script for the cluster $($cluster.name): '$($clustervcfvms_string)' ." -Colour Cyan + Write-PowerManagementLogMessage -Type INFO -Message "Management virtual machines covered by the script for the cluster $($cluster.name): '$($clustervcfvms_string)' ." if ($clustercustomervms.count -ne 0) { $clustercustomervms_string = $clustercustomervms -join "; " - Write-PowerManagementLogMessage -Type INFO -Message "Virtual machines for the cluster $($cluster.name) that are not covered by the script: '$($clustercustomervms_string)'. These VMs will be stopped in a random order if the 'shutdownCustomerVm' flag is passed." -Colour Cyan + Write-PowerManagementLogMessage -Type INFO -Message "Virtual machines for the cluster $($cluster.name) that are not covered by the script: '$($clustercustomervms_string)'. These VMs will be stopped in a random order if the 'shutdownCustomerVm' flag is passed." } # Check if VMware Tools are running in the customer VMs - if not we could not stop them gracefully @@ -518,7 +518,7 @@ Try { } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot to connect to vCenter Server '$($vcServer.fqdn)'. The command returned the following error: '$vcConnectError'." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot to connect to vCenter Server '$($vcServer.fqdn)'. The command returned the following error: '$vcConnectError'." } } # Disconnect from the VC @@ -527,8 +527,8 @@ Try { } if ($VMwareToolsNotRunningVMs.count -ne 0) { $noToolsVMs = $VMwareToolsNotRunningVMs -join "; " - Write-PowerManagementLogMessage -Type WARNING -Message "There are some VMs that are not managed by VMware Cloud Foundation where VMware Tools isn't running. Unable to shut down these VMs:'$noToolsVMs'." -Colour cyan - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot proceed until these VMs are shut down manually. Shut them down manually and run the script again." -Colour Red + Write-PowerManagementLogMessage -Type WARNING -Message "There are some VMs that are not managed by VMware Cloud Foundation where VMware Tools isn't running. Unable to shut down these VMs:'$noToolsVMs'." + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot proceed until these VMs are shut down manually. Shut them down manually and run the script again." Exit } } @@ -536,15 +536,15 @@ Try { if ($clustercustomervms.count -ne 0) { $clustercustomervms_string = $clustercustomervms -join "; " if ($PsBoundParameters.ContainsKey("shutdownCustomerVm")) { - Write-PowerManagementLogMessage -Type WARNING -Message "Some VMs are still powered on. -shutdownCustomerVm is passed to the script." -Colour Yellow - Write-PowerManagementLogMessage -Type WARNING -Message "Hence shutting down VMs not managed by SDDC Manager to put the host in maintenance mode." -Colour Yellow - Write-PowerManagementLogMessage -Type WARNING -Message "The list of Non VCF management VMs: '$clustercustomervms_string'." -Colour Yellow + Write-PowerManagementLogMessage -Type WARNING -Message "Some VMs are still powered on. -shutdownCustomerVm is passed to the script." + Write-PowerManagementLogMessage -Type WARNING -Message "Hence shutting down VMs not managed by SDDC Manager to put the host in maintenance mode." + Write-PowerManagementLogMessage -Type WARNING -Message "The list of Non VCF management VMs: '$clustercustomervms_string'." # Stop Customer VMs with one call to VC: Stop-CloudComponent -server $vcServer.fqdn -user $vcUser -pass $vcPass -nodes $clustercustomervms -timeout 300 } else { - Write-PowerManagementLogMessage -Type WARNING -Message "Some VMs are still powered on. -shutdownCustomerVm is not passed to the script." -Colour Yellow - Write-PowerManagementLogMessage -Type WARNING -Message "Hence not shutting down VMs that are not managed by VMware Cloud Foundation: '$clustercustomervms_string'." -Colour Yellow - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot proceed until these VMs are shut down manually or the customer VM Shutdown option is set to true. Please take the necessary action and run the script again." -Colour Red + Write-PowerManagementLogMessage -Type WARNING -Message "Some VMs are still powered on. -shutdownCustomerVm is not passed to the script." + Write-PowerManagementLogMessage -Type WARNING -Message "Hence not shutting down VMs that are not managed by VMware Cloud Foundation: '$clustercustomervms_string'." + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot proceed until these VMs are shut down manually or the customer VM Shutdown option is set to true. Please take the necessary action and run the script again." Exit } } @@ -555,11 +555,11 @@ Try { Stop-CloudComponent -server $vcServer.fqdn -user $vcUser -pass $vcPass -nodes $nxtClusterEdgeNodes -timeout 600 } else { - Write-PowerManagementLogMessage -Type WARNING -Message "No NSX Edge nodes found for a given cluster '$($cluster.name)' . Skipping edge nodes shutdown..." -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "No NSX Edge nodes found for a given cluster '$($cluster.name)' . Skipping edge nodes shutdown..." } } else { - Write-PowerManagementLogMessage -Type WARNING -Message "'$($vcServer.fqdn)' might already be shut down. Skipping shutdown of $nsxtEdgeNodes..." -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "'$($vcServer.fqdn)' might already be shut down. Skipping shutdown of $nsxtEdgeNodes..." } @@ -581,7 +581,7 @@ Try { } } if (-not $allothervcdown) { - Write-PowerManagementLogMessage -Type WARNING -Message "NSX Manager is shared across workload domains. Some of the vCenter Server instances for these workload domains are still running. Hence, not shutting down NSX Manager at this point." -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "NSX Manager is shared across workload domains. Some of the vCenter Server instances for these workload domains are still running. Hence, not shutting down NSX Manager at this point." } else { if ($lastelement) { Stop-CloudComponent -server $mgmtVcServer.fqdn -user $mgmtvcUser -pass $mgmtvcPass -nodes $nsxtNodes -timeout 600 @@ -600,11 +600,11 @@ Try { Set-Retreatmode -server $vcServer.fqdn -user $vcUser -pass $vcPass -cluster $cluster.name -mode enable } else { - Write-PowerManagementLogMessage -Type WARNING -Message "'$($vcServer.fqdn)' might already be shut down. Skipping putting the cluster in retreat mode..." -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "'$($vcServer.fqdn)' might already be shut down. Skipping putting the cluster in retreat mode..." } # Waiting for vCLS VMs to be stopped for ($retries*10) seconds - Write-PowerManagementLogMessage -Type INFO -Message "vCLS retreat mode has been set. vCLS shutdown will take some time, please wait..." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "vCLS retreat mode has been set. vCLS shutdown will take some time, please wait..." $counter = 0 $retries = 10 $sleepTime = 30 @@ -620,7 +620,7 @@ Try { } } if ($counter -eq $retries) { - Write-PowerManagementLogMessage -Type ERROR -Message "The vCLS VMs were not shut down within the expected time. Stopping the script execution." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "The vCLS VMs were not shut down within the expected time. Stopping the script execution." Exit } @@ -630,30 +630,30 @@ Try { $RemoteVMs = @() $RemoteVMs = Get-poweronVMsOnRemoteDS -server $vcServer.fqdn -user $vcUser -pass $vcPass -clustertocheck $cluster.name if($RemoteVMs.count -eq 0) { - Write-PowerManagementLogMessage -Type INFO -Message "All remote VMs are powered off." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "All remote VMs are powered off." } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Not all remote VMs are powered off : $($RemoteVMs.Name), Unable to proceed. Please stop the VMs running on vSAN HCI Mesh datastore shared by this cluster." -Colour RED + Write-PowerManagementLogMessage -Type ERROR -Message "Not all remote VMs are powered off : $($RemoteVMs.Name), Unable to proceed. Please stop the VMs running on vSAN HCI Mesh datastore shared by this cluster." } } if ( (Test-VsanHealth -cluster $cluster.name -server $vcServer.fqdn -user $vcUser -pass $vcPass) -eq 0) { - Write-PowerManagementLogMessage -Type INFO -Message "vSAN health is good." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "vSAN health is good." } else { - Write-PowerManagementLogMessage -Type WARNING -Message "The vSAN cluster isn't in a healthy state. Check the vSAN health status in vCenter Server '$($vcServer.fqdn)'. After vSAN health is restored, run the script again." -Colour Cyan - Write-PowerManagementLogMessage -Type WARNING -Message "If the script execution has reached ESXi vSAN shutdown previously, this warning is expected. Please continue by following the documentation of VMware Cloud Foundation. " -Colour Cyan - Write-PowerManagementLogMessage -Type ERROR -Message "The vSAN cluster isn't in a healthy state. Check the messages above for a solution." -Colour Red + Write-PowerManagementLogMessage -Type WARNING -Message "The vSAN cluster isn't in a healthy state. Check the vSAN health status in vCenter Server '$($vcServer.fqdn)'. After vSAN health is restored, run the script again." + Write-PowerManagementLogMessage -Type WARNING -Message "If the script execution has reached ESXi vSAN shutdown previously, this warning is expected. Please continue by following the documentation of VMware Cloud Foundation. " + Write-PowerManagementLogMessage -Type ERROR -Message "The vSAN cluster isn't in a healthy state. Check the messages above for a solution." Exit } if ( (Test-VsanObjectResync -cluster $cluster.name -server $vcServer.fqdn -user $vcUser -pass $vcPass) -eq 0) { - # Write-PowerManagementLogMessage -Type INFO -Message "vSAN object resynchronization is successful." -Colour Green + # Write-PowerManagementLogMessage -Type INFO -Message "vSAN object resynchronization is successful." } else { - Write-PowerManagementLogMessage -Type ERROR -Message "There is an active vSAN object resynchronization operation. Check your environment and run the script again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "There is an active vSAN object resynchronization operation. Check your environment and run the script again." Exit } } else { - Write-PowerManagementLogMessage -Type WARNING -Message "'$($vcServer.fqdn)' might already be shut down. Skipping the vSAN health check for cluster $($cluster.name)." -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "'$($vcServer.fqdn)' might already be shut down. Skipping the vSAN health check for cluster $($cluster.name)." } # Verify that there are no running VMs on the ESXis and shutdown the vSAN cluster. @@ -669,16 +669,16 @@ Try { } } if ($runningVMs.count) { - Write-PowerManagementLogMessage -Type WARNING -Message "Some VMs are still in powered-on state." -Colour Yellow - Write-PowerManagementLogMessage -Type WARNING -Message "Cannot proceed until all VMs are shut down. Shut them down manually and run the script again." -Colour Yellow - Write-PowerManagementLogMessage -Type ERROR -Message "The environment has running VMs: $($runningVMs). Could not continue with vSAN shutdown while there are running VMs. Exiting! " -Colour Red + Write-PowerManagementLogMessage -Type WARNING -Message "Some VMs are still in powered-on state." + Write-PowerManagementLogMessage -Type WARNING -Message "Cannot proceed until all VMs are shut down. Shut them down manually and run the script again." + Write-PowerManagementLogMessage -Type ERROR -Message "The environment has running VMs: $($runningVMs). Could not continue with vSAN shutdown while there are running VMs. Exiting! " } else { if ([float]$vcfVersion -lt [float]4.5) { # Stop vSphere HA to avoid "orphaned" VMs during vSAN shutdown if (!$(Set-VsphereHA -server $vcServer.fqdn -user $vcUser -pass $vcPass -cluster $cluster.name -disableHA)) { - Write-PowerManagementLogMessage -Type ERROR -Message "Could not disable vSphere High Availability for cluster '$cluster'. Exiting!" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Could not disable vSphere High Availability for cluster '$cluster'. Exiting!" } ## Actual vSAN and ESXi shutdown happens here - once we are sure that there are no VMs running on hosts @@ -703,7 +703,7 @@ Try { foreach ($esxiNode in $esxiDetails) { $HostConnectionState = Get-MaintenanceMode -server $esxiNode.fqdn -user $esxiNode.username -pass $esxiNode.password if ($HostConnectionState -eq "Maintenance") { - Write-PowerManagementLogMessage -Type ERROR -Message "$($esxiNode.fqdn) is in maintenance mode before cluster shutdown. Automation could not proceed. Check the vSphere Client for more details ." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "$($esxiNode.fqdn) is in maintenance mode before cluster shutdown. Automation could not proceed. Check the vSphere Client for more details ." Exit } } @@ -724,14 +724,14 @@ Try { #Verify if all ESXi hosts are down in here to conclude End of Shutdown sequence foreach ($esxiNode in $esxiDetails) { if (Test-EndpointConnection -server $esxiNode.fqdn -Port 443) { - Write-PowerManagementLogMessage -Type WARNING -Message "$($esxiNode.fqdn) is still up. Sleeping for $sleepTime seconds before next check..." -Colour Yellow + Write-PowerManagementLogMessage -Type WARNING -Message "$($esxiNode.fqdn) is still up. Sleeping for $sleepTime seconds before next check..." } else { $successcount++ } } if ($successcount -eq $esxiDetails.count) { - Write-PowerManagementLogMessage -Type INFO -Message "All Hosts have been shutdown successfully!" -Colour Green - Write-PowerManagementLogMessage -Type INFO -Message "End of the shutdown sequence!" -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "All Hosts have been shutdown successfully!" + Write-PowerManagementLogMessage -Type INFO -Message "End of the shutdown sequence!" Exit } else { Start-Sleep -s $sleepTime @@ -743,7 +743,7 @@ Try { Set-VsanClusterPowerStatus -server $vcServer.fqdn -user $vcUser -pass $vcPass -cluster $cluster.name -PowerStatus clusterPoweredOff foreach ($esxiNode in $esxiDetails) { if (Test-EndpointConnection -server $esxiNode.fqdn -Port 443) { - Write-PowerManagementLogMessage -Type ERROR -Message "$($esxiNode.fqdn) is still up. Check the FQDN or IP address, or the power state of the '$($esxiNode.fqdn)'." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "$($esxiNode.fqdn) is still up. Check the FQDN or IP address, or the power state of the '$($esxiNode.fqdn)'." Exit } } @@ -756,14 +756,14 @@ Try { # End of shutdown if ([float]$vcfVersion -lt [float]4.5) { - Write-PowerManagementLogMessage -Type INFO -Message "########################################################" -Colour Green - Write-PowerManagementLogMessage -Type INFO -Message "Note: ESXi hosts are still powered on. Please stop them manually." -Colour Green - Write-PowerManagementLogMessage -Type INFO -Message "End of the shutdown sequence for the specified cluster $($cluster.name)!" -Colour Green - Write-PowerManagementLogMessage -Type INFO -Message "########################################################" -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "########################################################" + Write-PowerManagementLogMessage -Type INFO -Message "Note: ESXi hosts are still powered on. Please stop them manually." + Write-PowerManagementLogMessage -Type INFO -Message "End of the shutdown sequence for the specified cluster $($cluster.name)!" + Write-PowerManagementLogMessage -Type INFO -Message "########################################################" } else { - Write-PowerManagementLogMessage -Type INFO -Message "########################################################" -Colour Green - Write-PowerManagementLogMessage -Type INFO -Message "End of the shutdown sequence for the specified cluster $($cluster.name)!" -Colour Green - Write-PowerManagementLogMessage -Type INFO -Message "########################################################" -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "########################################################" + Write-PowerManagementLogMessage -Type INFO -Message "End of the shutdown sequence for the specified cluster $($cluster.name)!" + Write-PowerManagementLogMessage -Type INFO -Message "########################################################" } } } @@ -777,7 +777,7 @@ Catch { # Startup procedures Try { if ($WorkloadDomain.type -eq "MANAGEMENT") { - Write-PowerManagementLogMessage -Type ERROR -Message "The specified workload domain '$sddcDomain' is the management domain. This script handles only VI workload domains. Exiting! " -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "The specified workload domain '$sddcDomain' is the management domain. This script handles only VI workload domains. Exiting! " Exit } @@ -795,13 +795,13 @@ Try { foreach ($esxiNode in $esxiDetails) { $status = Get-SSHEnabledStatus -server $esxiNode.fqdn -user $esxiNode.username -pass $esxiNode.password if (-Not $status) { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot open an SSH connection to host $($esxiNode.fqdn). If SSH is not enabled, follow the steps in the documentation to enable it." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot open an SSH connection to host $($esxiNode.fqdn). If SSH is not enabled, follow the steps in the documentation to enable it." Exit } } } catch { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot open an SSH connection to host $($esxiNode.fqdn), If SSH is not enabled, follow the steps in the documentation to enable it." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot open an SSH connection to host $($esxiNode.fqdn), If SSH is not enabled, follow the steps in the documentation to enable it." } # Take hosts out of maintenance mode @@ -824,7 +824,7 @@ Try { } foreach ($cluster in $ClusterDetails) { # Check ESXi status for each host - Write-PowerManagementLogMessage -Type INFO -Message "Checking the vSAN status of the ESXi hosts...." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "Checking the vSAN status of the ESXi hosts...." $esxiDetails = $esxiWorkloadCluster[$cluster.name] foreach ($esxiNode in $esxiDetails) { Invoke-EsxCommand -server $esxiNode.fqdn -user $esxiNode.username -pass $esxiNode.password -expected "Local Node Health State: HEALTHY" -cmd "esxcli vsan cluster get" @@ -841,9 +841,9 @@ Try { if (-not $VcStarted) { # Startup the Virtual Infrastructure Workload Domain vCenter Server Start-CloudComponent -server $mgmtVcServer.fqdn -user $mgmtvcUser -pass $mgmtvcPass -nodes $wldVC.Split(".")[0] -timeout 600 - Write-PowerManagementLogMessage -Type INFO -Message "Waiting for the vCenter Server services to start on '$($wldVC.Split(".")[0])'. It will take some time." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Waiting for the vCenter Server services to start on '$($wldVC.Split(".")[0])'. It will take some time." } else { - Write-PowerManagementLogMessage -Type INFO -Message "vCenter Server '$($wldVC.Split(".")[0])' is already started" -Colour Gre + Write-PowerManagementLogMessage -Type INFO -Message "vCenter Server '$($wldVC.Split(".")[0])' is already started" } $retries = 20 if ($DefaultVIServers) { @@ -860,7 +860,7 @@ Try { break } else { - Write-PowerManagementLogMessage -Type INFO -Message "The services on vCenter Server $wldVC are still starting. Please wait." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "The services on vCenter Server $wldVC are still starting. Please wait." Start-Sleep -s 60 } } @@ -868,7 +868,7 @@ Try { # Workaround for ESXis that do not communicate their Maintenance status to vCenter Server foreach ($esxiNode in $esxiDetails) { if ((Get-VMHost -name $esxiNode.fqdn).ConnectionState -eq "Maintenance") { - write-PowerManagementLogMessage -Type INFO -Message "Performing exit maintenance mode on '$($esxiNode.fqdn)' from vCenter Server." -Colour Yellow + write-PowerManagementLogMessage -Type INFO -Message "Performing exit maintenance mode on '$($esxiNode.fqdn)' from vCenter Server." (Get-VMHost -name $esxiNode.fqdn | Get-View).ExitMaintenanceMode_Task(0) | Out-Null } } @@ -878,12 +878,12 @@ Try { } Start-Sleep -s 60 $retries -= 1 - Write-PowerManagementLogMessage -Type INFO -Message "vCenter Server is still starting. Please wait." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "vCenter Server is still starting. Please wait." } } if ($service_status -eq $allWldVCs.count) { - Write-PowerManagementLogMessage -Type INFO -Message "vCenter Server has been started successfully." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "vCenter Server has been started successfully." if ([float]$vcfVersion -gt [float]4.4) { #Start ESXi hosts here Write-Host ""; @@ -902,18 +902,18 @@ Try { } $proceed = Read-Host $WarningString if (-Not $proceed) { - Write-PowerManagementLogMessage -Type WARNING -Message "None of the options is selected. Default is 'No', hence stopping script execution." -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "None of the options is selected. Default is 'No', hence stopping script execution." Exit } else { if (($proceed -match "no") -or ($proceed -match "yes")) { if ($proceed -match "no") { - Write-PowerManagementLogMessage -Type WARNING -Message "Stopping script execution because the input is 'No'." -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "Stopping script execution because the input is 'No'." Exit } } else { - Write-PowerManagementLogMessage -Type WARNING -Message "Pass the right string - either 'Yes' or 'No'." -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "Pass the right string - either 'Yes' or 'No'." Exit } } @@ -921,7 +921,7 @@ Try { $esxiDetails = $esxiWorkloadCluster[$cluster.name] foreach ($esxiNode in $esxiDetails) { if (!(Test-EndpointConnection -server $esxiNode.fqdn -Port 443)) { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot communicate with the host $($esxiNode.fqdn). Check the FQDN or IP address, or the power state of '$($esxiNode.fqdn)'." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot communicate with the host $($esxiNode.fqdn). Check the FQDN or IP address, or the power state of '$($esxiNode.fqdn)'." Exit } } @@ -935,36 +935,36 @@ Try { foreach ($esxiNode in $esxiDetails) { $HostConnectionState = Get-MaintenanceMode -server $esxiNode.fqdn -user $esxiNode.username -pass $esxiNode.password if ($HostConnectionState -eq "Maintenance") { - Write-PowerManagementLogMessage -Type ERROR -Message "$($esxiNode.fqdn) is still in maintenance mode even after cluster restart. Check the vSphere Client and take the necessary actions." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "$($esxiNode.fqdn) is still in maintenance mode even after cluster restart. Check the vSphere Client and take the necessary actions." Exit } } } if ((Test-VsanHealth -cluster $cluster.name -server $vcServer.fqdn -user $vcUser -pass $vcPass) -eq 0) { - Write-PowerManagementLogMessage -Type INFO -Message "Cluster health is good." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "Cluster health is good." } else { - Write-PowerManagementLogMessage -Type ERROR -Message "The cluster isn't in a healthy state. Check your environment and run the script again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "The cluster isn't in a healthy state. Check your environment and run the script again." Exit } # Check the health and sync status of the vSAN cluster if ((Test-VsanObjectResync -cluster $cluster.name -server $vcServer.fqdn -user $vcUser -pass $vcPass) -eq 0) { - # Write-PowerManagementLogMessage -Type INFO -Message "vSAN object resynchronization is successful." -Colour Green + # Write-PowerManagementLogMessage -Type INFO -Message "vSAN object resynchronization is successful." } else { - Write-PowerManagementLogMessage -Type ERROR -Message "vSAN object resynchronization has failed. Check your environment and run the script again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "vSAN object resynchronization has failed. Check your environment and run the script again." Exit } if ([float]$vcfVersion -lt [float]4.5) { # Start vSphere HA to avoid triggering a "Cannot find vSphere HA master agent" error. if (!$(Set-VsphereHA -server $vcServer.fqdn -user $vcUser -pass $vcPass -cluster $cluster.name -enableHA)) { - Write-PowerManagementLogMessage -Type ERROR -Message "Could not enable vSphere High Availability for cluster '$cluster'. Exiting!" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Could not enable vSphere High Availability for cluster '$cluster'. Exiting!" } } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Some of the vCenter Server instances are not started. Check the vSphere Client for more details and run the script again after all vCenter Server instances are up and running." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Some of the vCenter Server instances are not started. Check the vSphere Client for more details and run the script again after all vCenter Server instances are up and running." Exit } } @@ -972,7 +972,7 @@ Try { foreach ($cluster in $ClusterDetails) { # Startup vSphere Cluster Services Virtual Machines in Virtual Infrastructure Workload Domain Set-Retreatmode -server $vcServer.fqdn -user $vcUser -pass $vcPass -cluster $cluster.name -mode disable - Write-PowerManagementLogMessage -Type INFO -Message "vCLS retreat mode has been set. vCLS startup will take some time. Please wait! " -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "vCLS retreat mode has been set. vCLS startup will take some time. Please wait! " } $index = 1 @@ -993,7 +993,7 @@ Try { } } if ($counter -eq $retries) { - Write-PowerManagementLogMessage -Type ERROR -Message "The vCLS VMs were not started within the expected time. Stopping script execution!" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "The vCLS VMs were not started within the expected time. Stopping script execution!" Exit } [Array]$clustervclsvms = @() @@ -1014,7 +1014,7 @@ Try { if ($index -eq 1) { # Get fresh token from SDDC manager $StatusMsg = Request-VCFToken -fqdn $server -username $user -password $pass -WarningAction SilentlyContinue -ErrorAction SilentlyContinue -WarningVariable WarnMsg -ErrorVariable ErrorMsg - if ($StatusMsg) { Write-PowerManagementLogMessage -Type INFO -Message $StatusMsg } if ($WarnMsg) { Write-PowerManagementLogMessage -Type WARNING -Message $WarnMsg -Colour Magenta } if ($ErrorMsg) { Write-PowerManagementLogMessage -Type ERROR -Message $ErrorMsg -Colour Red } + if ($StatusMsg) { Write-PowerManagementLogMessage -Type INFO -Message $StatusMsg } if ($WarnMsg) { Write-PowerManagementLogMessage -Type WARNING -Message $WarnMsg } if ($ErrorMsg) { Write-PowerManagementLogMessage -Type ERROR -Message $ErrorMsg } # Get NSX-T Details once VC is started ## Gather NSX Manager Cluster Details @@ -1039,7 +1039,7 @@ Try { } } if ($counter -eq $retries) { - Write-PowerManagementLogMessage -Type ERROR -Message "SDDC Manager did not manage to retrieve NSX-T Data Center information. Please check the LCM log file for errors. Stopping the script execution!" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "SDDC Manager did not manage to retrieve NSX-T Data Center information. Please check the LCM log file for errors. Stopping the script execution!" Exit } $nsxtMgrfqdn = $nsxtCluster.vipFqdn @@ -1064,11 +1064,11 @@ Try { # Startup the NSX Manager Nodes for Virtual Infrastructure Workload Domain Start-CloudComponent -server $mgmtVcServer.fqdn -user $mgmtvcUser -pass $mgmtvcPass -nodes $nsxtNodes -timeout 600 if (!(Wait-ForStableNsxtClusterStatus -server $nsxtMgrfqdn -user $nsxMgrVIP.adminUser -pass $nsxMgrVIP.adminPassword)) { - Write-PowerManagementLogMessage -Type ERROR -Message "The NSX Manager cluster is not in 'STABLE' state. Exiting!" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "The NSX Manager cluster is not in 'STABLE' state. Exiting!" Exit } } else { - Write-PowerManagementLogMessage -Type INFO -Message "NSX Manager is already started." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "NSX Manager is already started." } } @@ -1088,36 +1088,36 @@ Try { } } catch { - Write-PowerManagementLogMessage -Type WARNING -Message "Cannot fetch information about NSX Edge nodes." -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "Cannot fetch information about NSX Edge nodes." } if ($nxtClusterEdgeNodes.count -ne 0) { Start-CloudComponent -server $vcServer.fqdn -user $vcUser -pass $vcPass -nodes $nxtClusterEdgeNodes -timeout 600 } else { - Write-PowerManagementLogMessage -Type WARNING -Message "No NSX Edge nodes found. Skipping edge nodes startup for vSAN cluster '$($cluster.name)'!" -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "No NSX Edge nodes found. Skipping edge nodes startup for vSAN cluster '$($cluster.name)'!" } # End of startup $vcfvms_string = "" $vcfvms_string = ($clustervcfvms | select -Unique) -join "; " - Write-PowerManagementLogMessage -Type INFO -Message "##################################################################################" -Colour Green - Write-PowerManagementLogMessage -Type INFO -Message "The following components have been started: $vcfvms_string , " -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "##################################################################################" + Write-PowerManagementLogMessage -Type INFO -Message "The following components have been started: $vcfvms_string , " if ([float]$vcfVersion -lt [float]4.5) { - Write-PowerManagementLogMessage -Type INFO -Message "vSphere High Availability has been enabled by the script. Disable it per your environment's design." -Colour Cyan + Write-PowerManagementLogMessage -Type INFO -Message "vSphere High Availability has been enabled by the script. Disable it per your environment's design." } - Write-PowerManagementLogMessage -Type INFO -Message "Check the list above and start any additional VMs, that are required, before you proceed with workload startup!" -Colour Green - Write-PowerManagementLogMessage -Type INFO -Message "Use the following command to automatically start VMs" -Colour Yellow - Write-PowerManagementLogMessage -Type INFO -Message "Start-CloudComponent -server $($vcServer.fqdn) -user $vcUser -pass $vcPass -nodes -timeout 600" -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Check the list above and start any additional VMs, that are required, before you proceed with workload startup!" + Write-PowerManagementLogMessage -Type INFO -Message "Use the following command to automatically start VMs" + Write-PowerManagementLogMessage -Type INFO -Message "Start-CloudComponent -server $($vcServer.fqdn) -user $vcUser -pass $vcPass -nodes -timeout 600" if ([float]$vcfVersion -lt [float]4.5) { - Write-PowerManagementLogMessage -Type INFO -Message "If you have enabled SSH for the ESXi hosts through SDDC manager, disable it at this point." -Colour Cyan + Write-PowerManagementLogMessage -Type INFO -Message "If you have enabled SSH for the ESXi hosts through SDDC manager, disable it at this point." } if ([float]$vcfVersion -gt [float]4.4) { - Write-PowerManagementLogMessage -Type INFO -Message "If you have disabled lockdown mode for the ESXi hosts in workload cluster, you can enable it at this point." -Colour Cyan + Write-PowerManagementLogMessage -Type INFO -Message "If you have disabled lockdown mode for the ESXi hosts in workload cluster, you can enable it at this point." } - Write-PowerManagementLogMessage -Type INFO -Message "##################################################################################" -Colour Green - Write-PowerManagementLogMessage -Type INFO -Message "End of startup sequence for the cluster '$($cluster.name)'!" -Colour Green - Write-PowerManagementLogMessage -Type INFO -Message "##################################################################################" -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "##################################################################################" + Write-PowerManagementLogMessage -Type INFO -Message "End of startup sequence for the cluster '$($cluster.name)'!" + Write-PowerManagementLogMessage -Type INFO -Message "##################################################################################" $index += 1 } } diff --git a/VMware.CloudFoundation.PowerManagement.psd1 b/VMware.CloudFoundation.PowerManagement.psd1 index 3bcab8f..f339aa2 100644 --- a/VMware.CloudFoundation.PowerManagement.psd1 +++ b/VMware.CloudFoundation.PowerManagement.psd1 @@ -3,7 +3,7 @@ # Module manifest for module 'VMware.CloudFoundation.PowerManagement' # Generated by: Broadcom -# Generated on: 2023-12-05 +# Generated on: 2024-02-07 @{ @@ -11,7 +11,7 @@ RootModule = 'VMware.CloudFoundation.PowerManagement.psm1' # Version number of this module. - ModuleVersion = '1.4.1.1002' + ModuleVersion = '1.4.1.1003' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/VMware.CloudFoundation.PowerManagement.psm1 b/VMware.CloudFoundation.PowerManagement.psm1 index b215e84..d48fa2c 100644 --- a/VMware.CloudFoundation.PowerManagement.psm1 +++ b/VMware.CloudFoundation.PowerManagement.psm1 @@ -109,7 +109,7 @@ Function Stop-CloudComponent { $pass = Get-Password -User $user -Password $pass Try { - Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Stop-CloudComponent cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Stop-CloudComponent cmdlet." $checkServer = (Test-EndpointConnection -server $server -Port 443) if ($checkServer) { Write-PowerManagementLogMessage -Type INFO -Message "Connecting to '$server'..." @@ -127,7 +127,7 @@ Function Stop-CloudComponent { if (Get-VM | Where-Object { $_.Name -eq $node }) { $vm_obj = Get-VMGuest -Server $server -VM $node -ErrorAction SilentlyContinue if ($vm_obj.State -eq 'NotRunning') { - Write-PowerManagementLogMessage -Type INFO -Message "Node '$node' is already powered off." -Colour Cyan + Write-PowerManagementLogMessage -Type INFO -Message "Node '$node' is already powered off." Continue } Write-PowerManagementLogMessage -Type INFO -Message "Attempting to shut down node '$node'..." @@ -144,15 +144,15 @@ Function Stop-CloudComponent { $vm_obj = Get-VMGuest -Server $server -VM $node -ErrorAction SilentlyContinue } if ($count -gt $timeout) { - Write-PowerManagementLogMessage -Type ERROR -Message "Node '$node' did not shut down within the expected timeout $timeout value." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Node '$node' did not shut down within the expected timeout $timeout value." } else { - Write-PowerManagementLogMessage -Type INFO -Message "Node '$node' has shut down successfully." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "Node '$node' has shut down successfully." } } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Unable to find node '$node' in the inventory of server '$server'." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Unable to find node '$node' in the inventory of server '$server'." } } } @@ -171,7 +171,7 @@ Function Stop-CloudComponent { $count = 0 $vm_obj = Get-VMGuest -Server $server -VM $node.Name | Where-Object VmUid -match $server if ($vm_obj.State -eq 'NotRunning') { - Write-PowerManagementLogMessage -Type INFO -Message "Node '$($node.name)' is already powered off." -Colour Cyan + Write-PowerManagementLogMessage -Type INFO -Message "Node '$($node.name)' is already powered off." Continue } Write-PowerManagementLogMessage -Type INFO -Message "Attempting to shut down node '$($node.name)'..." @@ -188,33 +188,33 @@ Function Stop-CloudComponent { $vm_obj = Get-VMGuest -VM $node.Name | Where-Object VmUid -match $server } if ($count -gt $timeout) { - Write-PowerManagementLogMessage -Type ERROR -Message "Node '$($node.name)' did not shut down within the expected timeout $timeout value." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Node '$($node.name)' did not shut down within the expected timeout $timeout value." } else { - Write-PowerManagementLogMessage -Type INFO -Message "Node '$($node.name)' has shut down successfully." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "Node '$($node.name)' has shut down successfully." } } } } elseif ($pattern) { - Write-PowerManagementLogMessage -Type WARNING -Message "No nodes match pattern '$pattern' on host '$server'." -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "No nodes match pattern '$pattern' on host '$server'." } } Disconnect-VIServer -Server * -Force -Confirm:$false -WarningAction SilentlyContinue -ErrorAction SilentlyContinue | Out-Null } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" } } Catch { Debug-CatchWriterForPowerManagement -object $_ } Finally { - Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Stop-CloudComponent cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Stop-CloudComponent cmdlet." } } Export-ModuleMember -Function Stop-CloudComponent @@ -266,7 +266,7 @@ Function Start-CloudComponent { $pass = Get-Password -User $user -Password $pass Try { - Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Start-CloudComponent cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Start-CloudComponent cmdlet." $checkServer = (Test-EndpointConnection -server $server -Port 443) if ($checkServer) { Write-PowerManagementLogMessage -Type INFO -Message "Connecting to '$server'..." @@ -284,7 +284,7 @@ Function Start-CloudComponent { if (Get-VM | Where-Object { $_.Name -eq $node }) { $vm_obj = Get-VMGuest -Server $server -VM $node -ErrorAction SilentlyContinue if ($vm_obj.State -eq 'Running') { - Write-PowerManagementLogMessage -Type INFO -Message "Node '$node' is already in powered on." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "Node '$node' is already in powered on." Continue } Write-PowerManagementLogMessage -Type INFO -Message "Attempting to start up node '$node'..." @@ -298,15 +298,15 @@ Function Start-CloudComponent { $vm_obj = Get-VMGuest -Server $server -VM $node -ErrorAction SilentlyContinue } if ($count -gt $timeout) { - Write-PowerManagementLogMessage -Type ERROR -Message "Node '$node' did not start up within the expected timeout $timeout value." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Node '$node' did not start up within the expected timeout $timeout value." Break } else { - Write-PowerManagementLogMessage -Type INFO -Message "Node '$node' has started successfully." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "Node '$node' has started successfully." } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot find '$node' in the inventory of host '$server'." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot find '$node' in the inventory of host '$server'." } } } @@ -325,7 +325,7 @@ Function Start-CloudComponent { $count = 0 $vm_obj = Get-VMGuest -server $server -VM $node.Name | Where-Object VmUid -match $server if ($vm_obj.State -eq 'Running') { - Write-PowerManagementLogMessage -Type INFO -Message "Node '$($node.name)' is already powered on." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "Node '$($node.name)' is already powered on." Continue } @@ -339,32 +339,32 @@ Function Start-CloudComponent { $vm_obj = Get-VMGuest -Server $server -VM $node.Name | Where-Object VmUid -match $server } if ($count -gt $timeout) { - Write-PowerManagementLogMessage -Type ERROR -Message "Node '$($node.name)' did not start up within the expected timeout $timeout value." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Node '$($node.name)' did not start up within the expected timeout $timeout value." } else { - Write-PowerManagementLogMessage -Type INFO -Message "Node '$($node.name)' has started successfully." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "Node '$($node.name)' has started successfully." } } } elseif ($pattern) { - Write-PowerManagementLogMessage -Type WARNING -Message "No nodes match pattern '$pattern' on host '$server'." -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "No nodes match pattern '$pattern' on host '$server'." } } Disconnect-VIServer -Server * -Force -Confirm:$false -WarningAction SilentlyContinue -ErrorAction SilentlyContinue | Out-Null } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to host '$server'. Check your environment and try again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to host '$server'. Check your environment and try again." } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" } } Catch { Debug-CatchWriterForPowerManagement -object $_ } Finally { - Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Start-CloudComponent cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Start-CloudComponent cmdlet." } } Export-ModuleMember -Function Start-CloudComponent @@ -408,7 +408,7 @@ Function Set-MaintenanceMode { $pass = Get-Password -User $user -Password $pass Try { - Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Set-MaintenanceMode cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Set-MaintenanceMode cmdlet." $checkServer = (Test-EndpointConnection -server $server -Port 443) if ($checkServer) { Write-PowerManagementLogMessage -Type INFO -Message "Connecting to '$server'..." @@ -425,17 +425,17 @@ Function Set-MaintenanceMode { Get-View -Server $server -ViewType HostSystem -Filter @{"Name" = $server } | Where-Object { !$_.Runtime.InMaintenanceMode } | ForEach-Object { $_.EnterMaintenanceMode(0, $false, (new-object VMware.Vim.HostMaintenanceSpec -Property @{vsanMode = (new-object VMware.Vim.VsanHostDecommissionMode -Property @{objectAction = [VMware.Vim.VsanHostDecommissionModeObjectAction]::NoAction }) })) } | Out-Null $hostStatus = (Get-VMHost -Server $server) if ($hostStatus.ConnectionState -eq "Maintenance") { - Write-PowerManagementLogMessage -Type INFO -Message "Host '$server' has entered maintenance mode successfully." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "Host '$server' has entered maintenance mode successfully." } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Host '$server' did not enter maintenance mode. Check your environment and try again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Host '$server' did not enter maintenance mode. Check your environment and try again." } } elseif ($hostStatus.ConnectionState -eq "Maintenance") { - Write-PowerManagementLogMessage -Type INFO -Message "Host '$server' has already entered maintenance mode." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "Host '$server' has already entered maintenance mode." } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Host '$server' is not currently connected." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Host '$server' is not currently connected." } } @@ -446,34 +446,34 @@ Function Set-MaintenanceMode { Wait-Task $task | out-null $hostStatus = (Get-VMHost -Server $server) if ($hostStatus.ConnectionState -eq "Connected") { - Write-PowerManagementLogMessage -Type INFO -Message "Host '$server' has exited maintenance mode successfully." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "Host '$server' has exited maintenance mode successfully." } else { - Write-PowerManagementLogMessage -Type ERROR -Message "The host '$server' did not exit maintenance mode. Check your environment and try again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "The host '$server' did not exit maintenance mode. Check your environment and try again." } } elseif ($hostStatus.ConnectionState -eq "Connected") { - Write-PowerManagementLogMessage -Type INFO -Message "Host '$server' has already exited maintenance mode" -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Host '$server' has already exited maintenance mode" } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Host '$server' is not currently connected." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Host '$server' is not currently connected." } } Disconnect-VIServer -Server * -Force -Confirm:$false -WarningAction SilentlyContinue -ErrorAction SilentlyContinue | Out-Null } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" } } Catch { Debug-CatchWriterForPowerManagement -object $_ } Finally { - Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Set-MaintenanceMode cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Set-MaintenanceMode cmdlet." } } Export-ModuleMember -Function Set-MaintenanceMode @@ -509,7 +509,7 @@ Function Get-MaintenanceMode { $pass = Get-Password -User $user -Password $pass Try { - Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Get-MaintenanceMode cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Get-MaintenanceMode cmdlet." $checkServer = (Test-EndpointConnection -server $server -Port 443) if ($checkServer) { Write-PowerManagementLogMessage -Type INFO -Message "Connecting to '$server'..." @@ -524,18 +524,18 @@ Function Get-MaintenanceMode { return $hostStatus.ConnectionState } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again." } } Catch { Debug-CatchWriterForPowerManagement -object $_ } Finally { - Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Get-MaintenanceMode cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Get-MaintenanceMode cmdlet." } } Export-ModuleMember -Function Get-MaintenanceMode @@ -579,7 +579,7 @@ Function Set-DrsAutomationLevel { $pass = Get-Password -User $user -Password $pass Try { - Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Set-DrsAutomationLevel cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Set-DrsAutomationLevel cmdlet." $checkServer = (Test-EndpointConnection -server $server -Port 443) if ($checkServer) { @@ -592,36 +592,36 @@ Function Set-DrsAutomationLevel { $drsStatus = Get-Cluster -Name $cluster -ErrorAction SilentlyContinue if ($drsStatus) { if ($drsStatus.DrsAutomationLevel -eq $level) { - Write-PowerManagementLogMessage -Type INFO -Message "The vSphere DRS automation level for cluster '$cluster' is already '$level'." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "The vSphere DRS automation level for cluster '$cluster' is already '$level'." } else { $drsStatus = Set-Cluster -Cluster $cluster -DrsAutomationLevel $level -Confirm:$false if ($drsStatus.DrsAutomationLevel -eq $level) { - Write-PowerManagementLogMessage -Type INFO -Message "The vSphere DRS automation level for cluster '$cluster' has been set to '$level' successfully." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "The vSphere DRS automation level for cluster '$cluster' has been set to '$level' successfully." } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Failed to set the vSphere DRS automation level for cluster '$cluster' to '$level'." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Failed to set the vSphere DRS automation level for cluster '$cluster' to '$level'." } } Disconnect-VIServer -Server * -Force -Confirm:$false -WarningAction SilentlyContinue -ErrorAction SilentlyContinue | Out-Null } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Cluster '$cluster' not found on host '$server'. Check your environment and try again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cluster '$cluster' not found on host '$server'. Check your environment and try again." } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" } } Catch { Debug-CatchWriterForPowerManagement -object $_ } Finally { - Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Set-DrsAutomationLevel cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Set-DrsAutomationLevel cmdlet." } } Export-ModuleMember -Function Set-DrsAutomationLevel @@ -672,7 +672,7 @@ Function Set-VsanClusterPowerStatus { $pass = Get-Password -User $user -Password $pass Try { - Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Set-VsanClusterPowerStatus cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Set-VsanClusterPowerStatus cmdlet." $checkServer = (Test-EndpointConnection -server $server -Port 443) if ($checkServer) { @@ -713,15 +713,15 @@ Function Set-VsanClusterPowerStatus { if ($task.State -eq "Error"){ if ($task.ExtensionData.Info.Error.Fault.FaultMessage -like "VMware.Vim.LocalizableMessage") { - Write-PowerManagementLogMessage -Type ERROR -Message "'$($PowerStatus)' task exited with a localized error message. Go to the vSphere Client for details and to take the necessary actions." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "'$($PowerStatus)' task exited with a localized error message. Go to the vSphere Client for details and to take the necessary actions." } else { - Write-PowerManagementLogMessage -Type WARN -Message "'$($PowerStatus)' task exited with the Message:$($task.ExtensionData.Info.Error.Fault.FaultMessage) and Error: $($task.ExtensionData.Info.Error)." -Colour Cyan - Write-PowerManagementLogMessage -Type ERROR -Message "Go to the vSphere Client for details and to take the necessary actions." -Colour Red + Write-PowerManagementLogMessage -Type WARN -Message "'$($PowerStatus)' task exited with the Message:$($task.ExtensionData.Info.Error.Fault.FaultMessage) and Error: $($task.ExtensionData.Info.Error)." + Write-PowerManagementLogMessage -Type ERROR -Message "Go to the vSphere Client for details and to take the necessary actions." } } if ($task.State -eq "Success"){ - Write-PowerManagementLogMessage -Type INFO -Message "$PowerStatus task is completed successfully." -colour GREEN + Write-PowerManagementLogMessage -Type INFO -Message "$PowerStatus task is completed successfully." } else { Write-PowerManagementLogMessage -Type ERROR -Message "$PowerStatus task is blocked in $($task.State) state." } @@ -730,18 +730,18 @@ Function Set-VsanClusterPowerStatus { } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" } } Catch { Debug-CatchWriterForPowerManagement -object $_ } Finally { - Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Set-VsanClusterPowerStatus cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Set-VsanClusterPowerStatus cmdlet." } } Export-ModuleMember -Function Set-VsanClusterPowerStatus @@ -767,7 +767,7 @@ Function Invoke-VxrailClusterShutdown { ) Try { - Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Invoke-VxrailClusterShutdown cmdlet." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Invoke-VxrailClusterShutdown cmdlet." $checkServer = (Test-EndpointConnection -server $server -Port 443) if ($checkServer) { @@ -784,7 +784,7 @@ Function Invoke-VxrailClusterShutdown { $headers.Add("Authorization", "Basic $base64AuthInfo") $uri = "https://$server/rest/vxm/v1/cluster/shutdown" - Write-PowerManagementLogMessage -Type INFO -Message "Starting VxRail cluster shutdown dry run." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "Starting VxRail cluster shutdown dry run." $respond = Invoke-WebRequest -Method POST -Uri $uri -Headers $headers -Body $payloadTest -UseBasicParsing -SkipCertificateCheck if($respond.StatusCode -eq "202" -or $respond.StatusCode -eq "200") { $requestID = $respond.content | ConvertFrom-JSON @@ -804,14 +804,14 @@ Function Invoke-VxrailClusterShutdown { } if ($checkProgress.extension.passed -match "true") { - Write-PowerManagementLogMessage -Type INFO -Message "VxRail cluster shutdown dry run: SUCCEEDED." -Colour Green - Write-PowerManagementLogMessage -Type INFO -Message "Starting VxRail cluster shutdown." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "VxRail cluster shutdown dry run: SUCCEEDED." + Write-PowerManagementLogMessage -Type INFO -Message "Starting VxRail cluster shutdown." $respond = Invoke-WebRequest -Method POST -Uri $uri -Headers $headers -Body $payloadRun -UseBasicParsing -SkipCertificateCheck if ($respond.StatusCode -eq "202" -or $respond.StatusCode -eq "200") { return $true } else { - Write-PowerManagementLogMessage -Type ERROR -Message "VxRail cluster shutdown: FAILED" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "VxRail cluster shutdown: FAILED" } } else { $errorMsg = "" @@ -824,19 +824,19 @@ Function Invoke-VxrailClusterShutdown { $errorMsg = $errorMsg + "Label: $($errorElement.label),($($errorElement.checkResult)) `nMessage: $($errorElement.message)`n" } } - Write-PowerManagementLogMessage -Type ERROR -Message "VxRail cluster shutdown dry run: FAILED `n $errorMsg" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "VxRail cluster shutdown dry run: FAILED `n $errorMsg" } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "VxRail cluster shutdown: FAILED" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "VxRail cluster shutdown: FAILED" } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" } } Catch { Debug-CatchWriterForPowerManagement -object $_ } Finally { - Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Invoke-VxrailClusterShutdown cmdlet." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Invoke-VxrailClusterShutdown cmdlet." } } Export-ModuleMember -Function Invoke-VxrailClusterShutdown @@ -876,7 +876,7 @@ Function Get-poweronVMsOnRemoteDS { $pass = Get-Password -User $user -Password $pass Try { - Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Get-poweronVMsOnRemoteDS cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Get-poweronVMsOnRemoteDS cmdlet." $checkServer = (Test-EndpointConnection -server $server -Port 443) if ($checkServer) { @@ -912,18 +912,18 @@ Function Get-poweronVMsOnRemoteDS { return $PoweredOnVMs } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" } } Catch { Debug-CatchWriterForPowerManagement -object $_ } Finally { - Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Get-poweronVMsOnRemoteDS cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Get-poweronVMsOnRemoteDS cmdlet." } } Export-ModuleMember -Function Get-poweronVMsOnRemoteDS @@ -963,7 +963,7 @@ Function Test-LockdownMode { $pass = Get-Password -User $user -Password $pass Try { - Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Test-LockdownMode cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Test-LockdownMode cmdlet." $checkServer = (Test-EndpointConnection -server $server -Port 443) if ($checkServer) { @@ -978,46 +978,46 @@ Function Test-LockdownMode { $hostsWithLockdown = "" if ($hostsInCluster.count -ne 0) { foreach ($esxiHost in $hostsInCluster) { - Write-PowerManagementLogMessage -Type INFO -Message "Checking lockdown mode for $esxiHost ...." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Checking lockdown mode for $esxiHost ...." $lockdownStatus = (Get-VMHost -Name $esxiHost).ExtensionData.Config.LockdownMode if ($lockdownStatus -eq $null) { $checkServer = (Test-EndpointConnection -server $esxiHost -Port 443) if ($checkServer) { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot fetch information about lockdown mode for ESXi host $esxiHost!" -Colour RED + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot fetch information about lockdown mode for ESXi host $esxiHost!" } else { - Write-PowerManagementLogMessage -Type WARNING -Message "Cannot fetch information about lockdown mode. Host $esxiHost is not reachable." -Colour Cyan - Write-PowerManagementLogMessage -Type ERROR -Message "Check the status on the ESXi host $esxiHost!" -Colour RED + Write-PowerManagementLogMessage -Type WARNING -Message "Cannot fetch information about lockdown mode. Host $esxiHost is not reachable." + Write-PowerManagementLogMessage -Type ERROR -Message "Check the status on the ESXi host $esxiHost!" } } else { if ($lockdownStatus -ne "lockdownDisabled") { - Write-PowerManagementLogMessage -Type WARNING -Message "Lockdown mode is enabled for ESXi host $esxiHost" -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "Lockdown mode is enabled for ESXi host $esxiHost" $hostsWithLockdown += ", $esxiHost" } } } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Cluster $cluster is not present on server $server. Check the input to the cmdlet." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cluster $cluster is not present on server $server. Check the input to the cmdlet." } if ([string]::IsNullOrEmpty($hostsWithLockdown)) { - Write-PowerManagementLogMessage -Type INFO -Message "Cluster $cluster does not have ESXi hosts in lockdown mode." -Colour GREEN + Write-PowerManagementLogMessage -Type INFO -Message "Cluster $cluster does not have ESXi hosts in lockdown mode." } else { - Write-PowerManagementLogMessage -Type INFO -Message "The following ESXi hosts are in lockdown mode: $hostsWithLockdown. Disable lockdown mode to continue." -Colour Red - Write-PowerManagementLogMessage -Type ERROR -Message "Some hosts are in lockdown mode. Disable lockdown mode to continue." -Colour Red + Write-PowerManagementLogMessage -Type INFO -Message "The following ESXi hosts are in lockdown mode: $hostsWithLockdown. Disable lockdown mode to continue." + Write-PowerManagementLogMessage -Type ERROR -Message "Some hosts are in lockdown mode. Disable lockdown mode to continue." } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again." } } Catch { Debug-CatchWriterForPowerManagement -object $_ } Finally { - Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Test-LockdownMode cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Test-LockdownMode cmdlet." } } Export-ModuleMember -Function Test-LockdownMode @@ -1061,7 +1061,7 @@ Function Get-VMRunningStatus { $pass = Get-Password -User $user -Password $pass Try { - Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Get-VMRunningStatus cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Get-VMRunningStatus cmdlet." $checkServer = (Test-EndpointConnection -server $server -Port 443) if ($checkServer) { Write-PowerManagementLogMessage -Type INFO -Message "Connecting to '$server'..." @@ -1073,7 +1073,7 @@ Function Get-VMRunningStatus { Write-PowerManagementLogMessage -Type INFO -Message "Connected to host '$server' and checking if nodes named '$pattern' are in the '$($status.ToUpper())' state..." $nodes = Get-VM | Where-Object Name -match $pattern | Select-Object Name, PowerState, VMHost if ($nodes.Name.Count -eq 0) { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot find nodes matching pattern '$pattern' in the inventory of host '$server'." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot find nodes matching pattern '$pattern' in the inventory of host '$server'." } else { foreach ($node in $nodes) { @@ -1092,18 +1092,18 @@ Function Get-VMRunningStatus { Disconnect-VIServer -Server * -Force -Confirm:$false -WarningAction SilentlyContinue -ErrorAction SilentlyContinue | Out-Null } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" } } Catch { Debug-CatchWriterForPowerManagement -object $_ } Finally { - Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Get-VMRunningStatus cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Get-VMRunningStatus cmdlet." } } Export-ModuleMember -Function Get-VMRunningStatus @@ -1147,7 +1147,7 @@ Function Invoke-EsxCommand { $pass = Get-Password -User $user -Password $pass Try { - Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Invoke-EsxCommand cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Invoke-EsxCommand cmdlet." $password = ConvertTo-SecureString $pass -AsPlainText -Force $Cred = New-Object System.Management.Automation.PSCredential ($user, $password) Write-PowerManagementLogMessage -Type INFO -Message "Connecting to '$server'..." @@ -1157,29 +1157,29 @@ Function Invoke-EsxCommand { $commandOutput = Invoke-SSHCommand -Index $session.SessionId -Command $cmd -Timeout 900 if ($expected ) { if (($commandOutput.Output -match $expected)) { - Write-PowerManagementLogMessage -Type INFO -Message "Command '$cmd' completed with expected output on server '$server'." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "Command '$cmd' completed with expected output on server '$server'." } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Failure. The `"$($expected)`" is not present in `"$($commandOutput.Output)`" output" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Failure. The `"$($expected)`" is not present in `"$($commandOutput.Output)`" output" } } elseif ($commandOutput.exitStatus -eq 0) { - Write-PowerManagementLogMessage -Type INFO -Message "Success. The command completed successfully." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "Success. The command completed successfully." } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Failure. The command could not be run." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Failure. The command could not be run." } Remove-SSHSession -Index $session.SessionId | Out-Null } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." } } Catch { Debug-CatchWriterForPowerManagement -object $_ } Finally { - Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Invoke-EsxCommand cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Invoke-EsxCommand cmdlet." } } Export-ModuleMember -Function Invoke-EsxCommand @@ -1215,7 +1215,7 @@ Function Get-SSHEnabledStatus { $pass = Get-Password -User $user -Password $pass Try { - Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Get-SSHEnabledStatus cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Get-SSHEnabledStatus cmdlet." $password = ConvertTo-SecureString $pass -AsPlainText -Force $Cred = New-Object System.Management.Automation.PSCredential ($user, $password) $checkServer = (Test-EndpointConnection -server $server -Port 443) @@ -1223,7 +1223,7 @@ Function Get-SSHEnabledStatus { Write-PowerManagementLogMessage -Type INFO -Message "Attempting to open an SSH connection to server '$server'..." $session = New-SSHSession -ComputerName $server -Credential $Cred -Force -WarningAction SilentlyContinue -ErrorAction SilentlyContinue if ($session) { - Write-PowerManagementLogMessage -Type INFO -Message "SSH is enabled on '$server'." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "SSH is enabled on '$server'." Remove-SSHSession -Index $session.SessionId | Out-Null return $True } @@ -1232,14 +1232,14 @@ Function Get-SSHEnabledStatus { return $False } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot communicate with server '$server'. Check the power state of the server." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot communicate with server '$server'. Check the power state of the server." } } Catch { Debug-CatchWriterForPowerManagement -object $_ } Finally { - Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Get-SSHEnabledStatus cmdlet" -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Get-SSHEnabledStatus cmdlet" } } Export-ModuleMember -Function Get-SSHEnabledStatus @@ -1279,7 +1279,7 @@ Function Test-VsanHealth { $pass = Get-Password -User $user -Password $pass Try { - Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Test-VsanHealth cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Test-VsanHealth cmdlet." $checkServer = (Test-EndpointConnection -server $server -Port 443) if ($checkServer) { Write-PowerManagementLogMessage -Type INFO -Message "Connecting to '$server'..." @@ -1308,7 +1308,7 @@ Function Test-VsanHealth { } if (-Not $flag) { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot run the Test-VsanHealth cmdlet because the vSAN health service is not running." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot run the Test-VsanHealth cmdlet because the vSAN health service is not running." } else { Start-Sleep -s 60 @@ -1335,29 +1335,29 @@ Function Test-VsanHealth { $healthCheckResults += $healthCheckGroupResult } if ($health_status -eq 'GREEN' -and $results.OverallHealth -ne 'red') { - Write-PowerManagementLogMessage -Type INFO -Message "The vSAN health status for $cluster is good." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "The vSAN health status for $cluster is good." return 0 } else { - Write-PowerManagementLogMessage -Type ERROR -Message "The vSAN health status for $cluster is bad." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "The vSAN health status for $cluster is bad." return 1 } Disconnect-VIServer -Server * -Force -Confirm:$false -WarningAction SilentlyContinue -ErrorAction SilentlyContinue | Out-Null } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" } } Catch { Debug-CatchWriterForPowerManagement -object $_ } Finally { - Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Test-VsanHealth cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Test-VsanHealth cmdlet." } } Export-ModuleMember -Function Test-VsanHealth @@ -1397,7 +1397,7 @@ Function Test-VsanObjectResync { $pass = Get-Password -User $user -Password $pass Try { - Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Test-VsanObjectResync cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Test-VsanObjectResync cmdlet." $checkServer = (Test-EndpointConnection -server $server -Port 443) if ($checkServer) { Write-PowerManagementLogMessage -Type INFO -Message "Connecting to '$server'..." @@ -1410,28 +1410,28 @@ Function Test-VsanObjectResync { $no_resyncing_objects = Get-VsanResyncingComponent -Server $server -cluster $cluster -ErrorAction Ignore Write-PowerManagementLogMessage -Type INFO -Message "Number of resynchronizing objects: $no_resyncing_objects." if ($no_resyncing_objects.count -eq 0) { - Write-PowerManagementLogMessage -Type INFO -Message "No resynchronizing objects." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "No resynchronizing objects." return 0 } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Resynchronizing objects in progress..." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Resynchronizing objects in progress..." return 1 } Disconnect-VIServer -Server * -Force -Confirm:$false -WarningAction SilentlyContinue -ErrorAction SilentlyContinue | Out-Null } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" } } Catch { Debug-CatchWriterForPowerManagement -object $_ } Finally { - Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Test-VsanObjectResync cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Test-VsanObjectResync cmdlet." } } Export-ModuleMember -Function Test-VsanObjectResync @@ -1494,7 +1494,7 @@ Function Get-VMsWithPowerStatus { Try { - if(-not $silence) {Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Get-VMsWithPowerStatus cmdlet." -Colour Yellow} + if(-not $silence) {Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Get-VMsWithPowerStatus cmdlet."} $checkServer = (Test-EndpointConnection -server $server -Port 443) if ($checkServer) { if(-not $silence) { Write-PowerManagementLogMessage -Type INFO -Message "Connecting to '$server'..."} @@ -1526,18 +1526,18 @@ Function Get-VMsWithPowerStatus { Return $no_of_vms } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" } } Catch { Debug-CatchWriterForPowerManagement -object $_ } Finally { - if(-not $silence) {Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Get-VMsWithPowerStatus cmdlet." -Colour Yellow} + if(-not $silence) {Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Get-VMsWithPowerStatus cmdlet."} } } Export-ModuleMember -Function Get-VMsWithPowerStatus @@ -1585,7 +1585,7 @@ Function Get-VamiServiceStatus { Try { if (-Not $nolog) { - Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Get-VAMIServiceStatus cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Get-VAMIServiceStatus cmdlet." } $checkServer = (Test-EndpointConnection -server $server -Port 443) if ($checkServer) { @@ -1606,7 +1606,7 @@ Function Get-VamiServiceStatus { Start-Sleep -s 60 $retries -= 1 if (-Not $nolog) { - Write-PowerManagementLogMessage -Type INFO -Message "Connecting to the vSphere Automation API endpoint might take some time. Please wait." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Connecting to the vSphere Automation API endpoint might take some time. Please wait." } } if ($flag) { @@ -1615,11 +1615,11 @@ Function Get-VamiServiceStatus { return $serviceStatus.state } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Testing the connection to server '$server' has failed. Check your details and try again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Testing the connection to server '$server' has failed. Check your details and try again." } } Catch { @@ -1631,7 +1631,7 @@ Function Get-VamiServiceStatus { } Disconnect-CisServer -Server * -Force -Confirm:$false -WarningAction SilentlyContinue -ErrorAction SilentlyContinue | Out-Null if (-Not $nolog) { - Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Get-VAMIServiceStatus cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Get-VAMIServiceStatus cmdlet." } } } @@ -1685,7 +1685,7 @@ Function Set-VamiServiceStatus { Try { if (-Not $nolog) { - Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Set-VamiServiceStatus cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Set-VamiServiceStatus cmdlet." } # TODO check if 443 is the default communication port $checkServer = (Test-EndpointConnection -server $server -Port 443) @@ -1707,7 +1707,7 @@ Function Set-VamiServiceStatus { Start-Sleep -s 60 $retries -= 1 if (-Not $nolog) { - Write-PowerManagementLogMessage -Type INFO -Message "Connecting to the vSphere Automation API endpoint might take some time. Please wait." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Connecting to the vSphere Automation API endpoint might take some time. Please wait." } } if ($flag) { @@ -1717,39 +1717,39 @@ Function Set-VamiServiceStatus { $serviceStatus = $vMonAPI.Get($service, 0) if($serviceStatus.state -eq "STARTED") { if (-Not $nolog) { - Write-PowerManagementLogMessage -Type INFO -Message "Service '$service' is successfully started." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Service '$service' is successfully started." } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Could not start service '$service'." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Could not start service '$service'." } } elseif ($state -eq "stop") { $vMonAPI.Stop($service) $serviceStatus = $vMonAPI.Get($service, 0) if($serviceStatus.state -eq "STOPPED") { if (-Not $nolog) { - Write-PowerManagementLogMessage -Type INFO -Message "Service '$service' is successfully stopped." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Service '$service' is successfully stopped." } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Could not stop service '$service'." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Could not stop service '$service'." } } else { $vMonAPI.ReStart($service) $serviceStatus = $vMonAPI.Get($service, 0) if($serviceStatus.state -eq "STARTED") { if (-Not $nolog) { - Write-PowerManagementLogMessage -Type INFO -Message "Service '$service' is successfully restarted." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Service '$service' is successfully restarted." } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Could not restart service '$service'." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Could not restart service '$service'." } } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Testing the connection to server '$server' has failed. Check your details and try again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Testing the connection to server '$server' has failed. Check your details and try again." } } Catch { @@ -1761,7 +1761,7 @@ Function Set-VamiServiceStatus { } Disconnect-CisServer -Server * -Force -Confirm:$false -WarningAction SilentlyContinue -ErrorAction SilentlyContinue | Out-Null if (-Not $nolog) { - Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Set-VamiServiceStatus cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Set-VamiServiceStatus cmdlet." } } } @@ -1813,7 +1813,7 @@ Function Set-VsphereHA { $pass = Get-Password -User $user -Password $pass Try { - Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Set-VsphereHA cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Set-VsphereHA cmdlet." if ($(Test-EndpointConnection -server $server -Port 443)) { Write-PowerManagementLogMessage -Type INFO -Message "Connecting to '$server'..." if ($DefaultVIServers) { @@ -1837,7 +1837,7 @@ Function Set-VsphereHA { While (-not $completed) { # Check iteration number if ($retrycount -ge $Retries) { - Write-PowerManagementLogMessage -Type WARNING -Message "Set vSphere High Availability timeouted after $($SecondsDelay * $Retries) seconds. There are still reconfiguratons in progress." -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "Set vSphere High Availability timeouted after $($SecondsDelay * $Retries) seconds. There are still reconfiguratons in progress." return $false } $retryCount++ @@ -1852,11 +1852,11 @@ Function Set-VsphereHA { else { $completed = $true if ($(get-cluster -Name $cluster).HAEnabled) { - Write-PowerManagementLogMessage -Type INFO -Message "vSphere High Availability for cluster '$cluster' changed to 'Enabled'." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "vSphere High Availability for cluster '$cluster' changed to 'Enabled'." return $true } else { - Write-PowerManagementLogMessage -Type WARNING -Message "Failed to set vSphere High Availability for cluster '$cluster' to 'Enabled'." -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "Failed to set vSphere High Availability for cluster '$cluster' to 'Enabled'." return $false } } @@ -1874,7 +1874,7 @@ Function Set-VsphereHA { While (-not $completed) { # Check iteration number if ($retrycount -ge $Retries) { - Write-PowerManagementLogMessage -Type WARNING -Message "Set vSphere High Availability timeouted after $($SecondsDelay * $Retries) seconds. There are still reconfiguratons in progress." -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "Set vSphere High Availability timeouted after $($SecondsDelay * $Retries) seconds. There are still reconfiguratons in progress." return $false } $retryCount++ @@ -1889,11 +1889,11 @@ Function Set-VsphereHA { else { $completed = $true if (!$(get-cluster -Name $cluster).HAEnabled) { - Write-PowerManagementLogMessage -Type INFO -Message "Disabled vSphere High Availability for cluster '$cluster'." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "Disabled vSphere High Availability for cluster '$cluster'." return $true } else { - Write-PowerManagementLogMessage -Type WARNING -Message "Failed to disable vSphere High Availability for cluster '$cluster'." -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "Failed to disable vSphere High Availability for cluster '$cluster'." return $false } } @@ -1902,18 +1902,18 @@ Function Set-VsphereHA { } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again." } } Catch { Debug-CatchWriterForPowerManagement -object $_ } Finally { - Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Set-VsphereHA cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Set-VsphereHA cmdlet." } } @@ -1954,7 +1954,7 @@ Function Get-DrsAutomationLevel { $pass = Get-Password -User $user -Password $pass Try { - Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Get-DrsAutomationLevel cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Get-DrsAutomationLevel cmdlet." $checkServer = (Test-EndpointConnection -server $server -Port 443) if ($checkServer) { Write-PowerManagementLogMessage -Type INFO -Message "Connecting to '$server'..." @@ -1976,18 +1976,18 @@ Function Get-DrsAutomationLevel { return $clsdrsvalue } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" } } Catch { Debug-CatchWriterForPowerManagement -object $_ } Finally { - Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Get-DrsAutomationLevel cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Get-DrsAutomationLevel cmdlet." } } @@ -2036,7 +2036,7 @@ Function Set-Retreatmode { $pass = Get-Password -User $user -Password $pass Try { - Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Set-Retreatmode cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Set-Retreatmode cmdlet." $checkServer = (Test-EndpointConnection -server $server -Port 443) if ($checkServer) { Write-PowerManagementLogMessage -Type INFO -Message "Connecting to '$server'..." @@ -2054,38 +2054,38 @@ Function Set-Retreatmode { Write-PowerManagementLogMessage -Type INFO -Message "Advanced setting $advanced_setting is present." if ($mode -eq 'enable') { Get-AdvancedSetting -Entity $server -Name $advanced_setting | Set-AdvancedSetting -Value 'false' -Confirm:$false | out-null - Write-PowerManagementLogMessage -Type INFO -Message "Advanced setting $advanced_setting is set to false." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "Advanced setting $advanced_setting is set to false." } else { Get-AdvancedSetting -Entity $server -Name $advanced_setting | Set-AdvancedSetting -Value 'true' -Confirm:$false | Out-Null - Write-PowerManagementLogMessage -Type INFO -Message "Advanced setting $advanced_setting is set to true." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "Advanced setting $advanced_setting is set to true." } } else { if ($mode -eq 'enable') { New-AdvancedSetting -Entity $server -Name $advanced_setting -Value 'false' -Confirm:$false | Out-Null - Write-PowerManagementLogMessage -Type INFO -Message "Advanced setting $advanced_setting is set to false." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "Advanced setting $advanced_setting is set to false." } else { New-AdvancedSetting -Entity $server -Name $advanced_setting -Value 'true' -Confirm:$false | Out-Null - Write-PowerManagementLogMessage -Type INFO -Message "Advanced setting $advanced_setting is set to true." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "Advanced setting $advanced_setting is set to true." } } Disconnect-VIServer -Server * -Force -Confirm:$false -WarningAction SilentlyContinue -ErrorAction SilentlyContinue | Out-Null } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" } } Catch { Debug-CatchWriterForPowerManagement -object $_ } Finally { - Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Set-Retreatmode cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Set-Retreatmode cmdlet." } } @@ -2143,7 +2143,7 @@ Function Get-VMToClusterMapping { $pass = Get-Password -User $user -Password $pass Try { - if(-not $silence) {Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Get-VMToClusterMapping cmdlet." -Colour Yellow} + if(-not $silence) {Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Get-VMToClusterMapping cmdlet."} $checkServer = (Test-EndpointConnection -server $server -Port 443) if ($checkServer) { if(-not $silence) {Write-PowerManagementLogMessage -Type INFO -Message "Connecting to '$server'..."} @@ -2167,18 +2167,18 @@ Function Get-VMToClusterMapping { } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot connect to server '$server'. Check your environment and try again." } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" } } Catch { Debug-CatchWriterForPowerManagement -object $_ } Finally { - if(-not $silence) {Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Get-VMToClusterMapping cmdlet." -Colour Yellow} + if(-not $silence) {Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Get-VMToClusterMapping cmdlet."} } } @@ -2215,7 +2215,7 @@ Function Wait-ForStableNsxtClusterStatus { $pass = Get-Password -User $user -Password $pass Try { - Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Wait-ForStableNsxtClusterStatus cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Wait-ForStableNsxtClusterStatus cmdlet." Write-PowerManagementLogMessage -Type INFO -Message "Waiting the cluster to become 'STABLE' for NSX Manager '$server'... This could take up to 20 min." # Create NSX-T header $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $pass))) # Create Basic Authentication Encoded Credentials @@ -2232,7 +2232,7 @@ Function Wait-ForStableNsxtClusterStatus { While (-not $completed) { # Check iteration number if ($retrycount -ge $Retries) { - Write-PowerManagementLogMessage -Type WARNING -Message "Request to '$uri' failed after $retryCount attempts." -Colour Cyan + Write-PowerManagementLogMessage -Type WARNING -Message "Request to '$uri' failed after $retryCount attempts." return $false } $retryCount++ @@ -2260,7 +2260,7 @@ Function Wait-ForStableNsxtClusterStatus { } else { $completed = $true - Write-PowerManagementLogMessage -Type INFO -Message "The state of the NSX Manager cluster '$server' is 'STABLE'." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "The state of the NSX Manager cluster '$server' is 'STABLE'." return $true } } @@ -2269,7 +2269,7 @@ Function Wait-ForStableNsxtClusterStatus { Debug-CatchWriterForPowerManagement -object $_ } Finally { - Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Wait-ForStableNsxtClusterStatus cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Wait-ForStableNsxtClusterStatus cmdlet." } } Export-ModuleMember -Function Wait-ForStableNsxtClusterStatus @@ -2313,7 +2313,7 @@ Function Get-EdgeNodeFromNSXManager { $pass = Get-Password -User $user -Password $pass Try { - Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Get-EdgeNodeFromNSXManager cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Get-EdgeNodeFromNSXManager cmdlet." if ( Test-EndpointConnection -server $server -Port 443 ) { Write-PowerManagementLogMessage -Type INFO -Message "Connecting to '$server'..." if ($DefaultNSXTServers) { @@ -2345,19 +2345,19 @@ Function Get-EdgeNodeFromNSXManager { return $edge_nodes_list } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check the console output for more details." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check the console output for more details." } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" } } Catch { Debug-CatchWriterForPowerManagement -object $_ } Finally { - Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Get-EdgeNodeFromNSXManager cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Get-EdgeNodeFromNSXManager cmdlet." } } Export-ModuleMember -Function Get-EdgeNodeFromNSXManager @@ -2393,7 +2393,7 @@ Function Get-NSXTComputeManagers { $pass = Get-Password -User $user -Password $pass Try { - Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Get-NSXTComputeManagers cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Get-NSXTComputeManagers cmdlet." if ( Test-EndpointConnection -server $server -Port 443 ) { Write-PowerManagementLogMessage -Type INFO -Message "Connecting to '$server'..." if ($DefaultNSXTServers) { @@ -2409,18 +2409,18 @@ Function Get-NSXTComputeManagers { return $compute_manager_list } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check the console output for more details." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check the console output for more details." } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again." } } Catch { Debug-CatchWriterForPowerManagement -object $_ } Finally { - Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Get-NSXTComputeManagers cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Get-NSXTComputeManagers cmdlet." } } Export-ModuleMember -Function Get-NSXTComputeManagers @@ -2460,7 +2460,7 @@ Function Get-TanzuEnabledClusterStatus { $pass = Get-Password -User $user -Password $pass Try { - Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Get-TanzuEnabledClusterStatus cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Starting the call to the Get-TanzuEnabledClusterStatus cmdlet." if ( Test-EndpointConnection -server $server -Port 443 ) { Write-PowerManagementLogMessage -Type INFO -Message "Connecting to '$server'..." if ($DefaultVIServers) { @@ -2470,7 +2470,7 @@ Function Get-TanzuEnabledClusterStatus { if ($DefaultVIServer.Name -eq $server) { $out = get-wmcluster -cluster $cluster -server $server -ErrorVariable ErrorMsg -ErrorAction SilentlyContinue if ($out.count -gt 0) { - Write-PowerManagementLogMessage -Type INFO -Message "vSphere with Tanzu is enabled." -Colour Green + Write-PowerManagementLogMessage -Type INFO -Message "vSphere with Tanzu is enabled." return $True } elseif (([string]$ErrorMsg -match "does not have Workloads enabled") -or ([string]::IsNullOrEmpty($ErrorMsg))) { @@ -2478,61 +2478,64 @@ Function Get-TanzuEnabledClusterStatus { return $False } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Cannot fetch information related to vSphere with Tanzu. ERROR message from 'get-wmcluster' command: '$ErrorMsg'" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Cannot fetch information related to vSphere with Tanzu. ERROR message from 'get-wmcluster' command: '$ErrorMsg'" } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check the console output for more details." -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check the console output for more details." } } else { - Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" -Colour Red + Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again" } } Catch { Debug-CatchWriterForPowerManagement -object $_ } Finally { - Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Get-TanzuEnabledClusterStatus cmdlet." -Colour Yellow + Write-PowerManagementLogMessage -Type INFO -Message "Completed the call to the Get-TanzuEnabledClusterStatus cmdlet." } } Export-ModuleMember -Function Get-TanzuEnabledClusterStatus ######### Start Useful Script Functions ########## Function Write-PowerManagementLogMessage { - <# - .SYNOPSIS - This cmdlet is used for logging messages. + <# + .SYNOPSIS + This cmdlet is used for logging messages. - .DESCRIPTION - This cmdlet is used for logging messages on the console. + .DESCRIPTION + This cmdlet is used for logging messages on the console. - .EXAMPLE - Write-PowerManagementLogMessage -Type ERROR -Message "Error message" -Colour Red - This logs the error message on the conolse in red colour and aborts execution immediately. + .EXAMPLE + Write-PowerManagementLogMessage -Type ERROR -Message "Error message" + Logs as a error message and uses the assigned color. - Write-PowerManagementLogMessage -Type WARNING -Message "Warning message" -Colour Cyan - This logs the warning message on the conosle in cyan colour and execution is continued. + Write-PowerManagementLogMessage -Type WARNING -Message "Warning message" + Logs as a warning message and uses the assigned color. - Write-PowerManagementLogMessage -Type INFO -Message "Info message" - This logs the information message on the conosle in white colour and execution is continued. + Write-PowerManagementLogMessage -Type INFO -Message "Info message" + Logs as a info message and uses the assigned color. - Write-PowerManagementLogMessage -Type EXCEPTION -Message "Exception message" -Colour Red - This logs the exception message on the conolse in red colour and aborts execution immediately. - - .PARAMETER Message - The message to be logged on the console. + Write-PowerManagementLogMessage -Type EXCEPTION -Message "Exception message" + Logs as an exception message and uses the assigned color. - .PARAMETER type - The type of the log message. The value can be one amongst ("INFO", "ERROR", "WARNING", "EXCEPTION"). + Write-PowerManagementLogMessage -Type INFO -Message "Exception message" -Colour Cyan + Logs as an exception message and uses the the specified color. + + .PARAMETER Message + The message to be logged on the console. - .PARAMETER Colour - The colour of the log message. + .PARAMETER type + The type of the log message. The value can be one amongst ("INFO", "ERROR", "WARNING", "EXCEPTION"). - .PARAMETER Skipnewline - This is used to skip new line while logging message. - #> + .PARAMETER Colour + The colour of the log message. This will override the default color for the log type. + + .PARAMETER Skipnewline + This is used to skip new line while logging message. + #> Param ( [Parameter (Mandatory = $true)] [AllowEmptyString()] [String]$Message, [Parameter (Mandatory = $false)] [ValidateSet("INFO", "ERROR", "WARNING", "EXCEPTION")] [String]$type, @@ -2540,8 +2543,25 @@ Function Write-PowerManagementLogMessage { [Parameter (Mandatory = $false)] [String]$Skipnewline ) $ErrorActionPreference = 'Stop' + if (!$Colour) { - $Colour = "White" + switch ($type) { + "INFO" { + $Colour = "Green" + } + "WARNING" { + $Colour = "Yellow" + } + "ERROR" { + $Colour = "Red" + } + "EXCEPTION" { + $Colour = "Magenta" + } + default { + $Colour = "White" + } + } } $timeStamp = Get-Date -Format "MM-dd-yyyy_HH:mm:ss" @@ -2551,13 +2571,13 @@ Function Write-PowerManagementLogMessage { Write-Host -NoNewline -ForegroundColor $Colour " $type $Message" } else { - Write-Host -ForegroundColor $colour " $Type $Message" + Write-Host -ForegroundColor $Colour " $Type $Message" } $logContent = '[' + $timeStamp + '] ' + $Type + ' ' + $Message if ($type -match "ERROR") { Write-Error -Message $Message } -} +} Export-ModuleMember -Function Write-PowerManagementLogMessage Function Debug-CatchWriterForPowerManagement {