Last active
July 21, 2022 09:07
-
-
Save SweetAsNZ/44f49028f4c33b84cca7072588319b53 to your computer and use it in GitHub Desktop.
Add-CPU To VM Guests With only 1 CPU
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Query VMWare for the List of All servers With Only 1 CPU Shut Them Down and Add Another CPU | |
# Assumes You Need To Shut The Server Down Which May Not Be The Case | |
$Date = ((Get-Date -Format "yyyy-MM-dd_HHmm_K").Replace(":","-").Replace("+","-")).ToString() # _$($Date).csv" _$($Date).txt" # Date for use in Filenames with TZ | |
$Server = 'VC1' | |
$VMCli = (Get-Module VMware.PowerCLI -ListAvailable).Name | |
if($VMCli -ne 'VMware.PowerCLI'){ | |
Write-Output "No VMWare CLI Found" | |
Install-Module VMware.PowerCLI -Scope AllUsers -AllowClobber #-Force | |
} | |
Import-Module VMware.PowerCLI | |
Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $false -InvalidCertificateAction Ignore -Confirm:$False | |
$UPN = cmd /c whoami /upn | |
$Cred = (Get-Credential -UserName $UPN -Message "Password") | |
Connect-VIServer -Credential $Cred -Server $Server # Requires the Credential function to be run once | |
# Gets VM Guests That Are Powered On With 1 CPU and 4GB or More of RAM | |
$VMs = Get-VM | Where {($_.PowerState -eq 'PoweredOn') -and ($_.NumCPU -le 1) -and ($_.MemoryGB -ge 4)} | Sort Name | |
$VMs | Select Name,NumCpu,MemoryGB | |
foreach ($Item in $VMs.Name) | |
{ | |
#$Item = 'ADFS2' # Testing | |
Shutdown-VMGuest -VM $Item -Confirm:$false #-WhatIf | |
Get-VM -Name $Item | Set-VM -NumCpu 2 -Confirm:$false | |
Start-VM -VM $Item -Confirm:$false | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment