Skip to main content

Posts

Showing posts from June, 2020

Calculate possible ceiling max values based on denominator

                    double higherMaxValue = 100; double maxValue = 1235; int cntDigit = maxValue >= 10 ? maxValue.ToString().Length : 1; int denominator = (int)Math.Pow(10, cntDigit - 1); higherMaxValue = maxValue + denominator - (maxValue % denominator); Console.WriteLine("maxValue:"+maxValue+" higherMaxValue:"+higherMaxValue);                       // maxValue:1235 higherMaxValue:2000

Suspend vSphere VMs with VMware PowerCLI

invoke-command -scriptblock { #using script block to bypass Execution Policy massage #install VMware.PowerCLI follow below steps #run powershell as admin #run the command to intall #Install-Module -Name VMware.PowerCLI #Install-Module VMware.PowerCLI -Scope CurrentUser #Set-executionpolicy remotesign #Import-Module VMware.PowerCLI #Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false #now install steps over restart powershell #To disable this warning and set your preference use the following command and restart PowerShell Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true -Confirm:$false #Connect to vCenter $Server = Connect-VIServer -Server 192.168.12.97 -User xxx@vsphere.local -Password xxxxxxxxxx #Gets the list of all Hosts in a specific folder $vmHosts = Get-VMHost -Location Singapore Foreach($vmHost in $vmHosts) { $vmHost.name $vms = Get-vmhost -name $vmHost.name | Get-VM | where { $_.PowerState -eq "PoweredOn"} Fo...