<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://wiki.towaso.de/index.php?action=history&amp;feed=atom&amp;title=Modify_Cpu_and_Memory_vSphere</id>
	<title>Modify Cpu and Memory vSphere - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.towaso.de/index.php?action=history&amp;feed=atom&amp;title=Modify_Cpu_and_Memory_vSphere"/>
	<link rel="alternate" type="text/html" href="http://wiki.towaso.de/index.php?title=Modify_Cpu_and_Memory_vSphere&amp;action=history"/>
	<updated>2026-04-17T12:18:01Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.1</generator>
	<entry>
		<id>http://wiki.towaso.de/index.php?title=Modify_Cpu_and_Memory_vSphere&amp;diff=20&amp;oldid=prev</id>
		<title>Tobias: Created page with &quot;Here is a short script to batch modify the CPU-Core count and Memory of a virtual machine using PowerCLI in a vSphere 6 environment (script adopted from the [https://code.vmwa...&quot;</title>
		<link rel="alternate" type="text/html" href="http://wiki.towaso.de/index.php?title=Modify_Cpu_and_Memory_vSphere&amp;diff=20&amp;oldid=prev"/>
		<updated>2020-06-10T09:52:36Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;Here is a short script to batch modify the CPU-Core count and Memory of a virtual machine using PowerCLI in a vSphere 6 environment (script adopted from the [https://code.vmwa...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Here is a short script to batch modify the CPU-Core count and Memory of a virtual machine using PowerCLI in a vSphere 6 environment (script adopted from the [https://code.vmware.com/forums/2530/vsphere-powercli VMware PowerCLI Forums]). The script uses a list of virtual machines which are to be modified including the socket count. &lt;br /&gt;
&lt;br /&gt;
Save the following script in a file with the name modifycpumem.ps1 in C:\&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Function Enable-MemHotAdd($vm){&lt;br /&gt;
    $vmview = Get-vm $vm | Get-View &lt;br /&gt;
    $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec&lt;br /&gt;
&lt;br /&gt;
    $extra = New-Object VMware.Vim.optionvalue&lt;br /&gt;
    $extra.Key=&amp;quot;mem.hotadd&amp;quot;&lt;br /&gt;
    $extra.Value=&amp;quot;true&amp;quot;&lt;br /&gt;
    $vmConfigSpec.extraconfig += $extra&lt;br /&gt;
&lt;br /&gt;
    $vmview.ReconfigVM($vmConfigSpec)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Function Enable-vCpuHotAdd($vm){&lt;br /&gt;
    $vmview = Get-vm $vm | Get-View &lt;br /&gt;
    $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec&lt;br /&gt;
&lt;br /&gt;
    $extra = New-Object VMware.Vim.optionvalue&lt;br /&gt;
    $extra.Key=&amp;quot;vcpu.hotadd&amp;quot;&lt;br /&gt;
    $extra.Value=&amp;quot;true&amp;quot;&lt;br /&gt;
    $vmConfigSpec.extraconfig += $extra&lt;br /&gt;
&lt;br /&gt;
    $vmview.ReconfigVM($vmConfigSpec)&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
$vmlist = Import-CSV C:\CPUList.csv&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
foreach ($item in $vmlist) {&lt;br /&gt;
    $vmname = $item.vmname&lt;br /&gt;
    Stop-VM -VM $vmname&lt;br /&gt;
    }&lt;br /&gt;
	&lt;br /&gt;
foreach ($item in $vmlist) {&lt;br /&gt;
&lt;br /&gt;
    $vmname = $item.vmname&lt;br /&gt;
    $sockets = $item.sockets&lt;br /&gt;
	$cpus = [int]$item.sockets * [int]$item.cores&lt;br /&gt;
    $mem = [int]$item.mem * 1024&lt;br /&gt;
    Enable-MemHotAdd $vmname&lt;br /&gt;
	Enable-vCpuHotAdd $vmname&lt;br /&gt;
    Set-VM -VM $vmname -CoresPerSocket $sockets -NumCPU $cpus -MemoryMB $mem -Confirm:$false&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
foreach ($item in $vmlist) {&lt;br /&gt;
    $vmname = $item.vmname&lt;br /&gt;
    Start-VM -VM $vmname &lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Create a csv-file with the colums    vmname,sockets,cores,mem,comment    and save this file with the name CPUList.csv in the C:\ folder. Modify the code for a different folder.&lt;br /&gt;
&lt;br /&gt;
After that start the PowerCLI console in admin mode.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then you need to connect to the vSphere of the VMs:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Connect-VIServer &amp;quot;Server&amp;quot; -User user -Password pass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After that you can execute the script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
.\modifycpumem.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In some environment you may need to set the execution policy before to run the ps1-script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
set-executionpolicy remotesigned &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also if you get a certificate error when connecting to the vsphere you can set the certificate check to ignore:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tobias</name></author>
		
	</entry>
</feed>