<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Script to set disk ,CPU and Memory for an existing VMs in VMware PowerCLI Discussions</title>
    <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Script-to-set-disk-CPU-and-Memory-for-an-existing-VMs/m-p/2953724#M110714</link>
    <description>&lt;P&gt;Try something like this.&lt;BR /&gt;&lt;BR /&gt;The new Harddisk is always applied.&lt;BR /&gt;&lt;BR /&gt;When the VM is powered off the CPU and Memory settings are always applied.&lt;BR /&gt;When the VM is powered on the hot-add and hot-remove settings are checked.&lt;BR /&gt;When a powered on VM doesn't have at least one of the required hot- settings it is exported to a CSV.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;# CSV layout: Name, CPU, Memory, Disk
#             VM1, 2, 4096, 40
#             VM2, 2, 4096, 40

$notEnabled = @()

Import-Csv -Path .\vm.csv -UseCulture -PipelineVariable row |
ForEach-Object -Process {
    $vm = Get-VM -Name $row.Name
    New-HardDisk -VM $vm -CapacityGB $row.Disk -Confirm:$false | Out-Null

    if($vm.PowerState -eq 'PoweredOn') {
        $cpuAdd = $cpuRemove = $memAdd = $true
        if($vm.CpuHotAddEnabled -and $row.CPU -gt $vm.NumCpu){
            Set-VM -VM $vm -NumCpu $row.CPU -Confirm:$false | Out-Null
        }
        else{
            $cpuAdd = $false
        }
        if($vm.CpuHotRemoveEnabled -and $row.CPU -lt $vm.NumCpu){
            Set-VM -VM $vm -NumCpu $row.CPU -Confirm:$false | Out-Null
        }
        else{
            $cpuRemove = $false
        }
        if($vm.MemoryHotAddEnabled -and $row.Memory -gt $vm.Memory){
            Set-VM -VM $vm -MemoryGB $row.Memory -Confirm:$false | Out-Null
        }
        else{
            $memAdd = $false
        }
    }
    else{
        Set-VM -VM $vm -NumCpu $row.CPU -MemoryGB $row.Memory -Confirm:$false | Out-Null
    }
    if($cpuAdd,$cpuRemove,$memAdd -notcontains $false){
        $notEnabled += New-Object -TypeName PSObject -Property ([ordered]@{
            VM = $vm.Name
            PowerState = $vm.PowerState
            CpuAdd = $cpuAdd
            CpuRemove = $cpuRemove
            MemAdd = $memAdd
        })
    }
}

$notEnabled | Export-Csv -Path .\notEnabled.csv -NoTypeInformation -UseCulture
&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 10 Feb 2023 13:31:22 GMT</pubDate>
    <dc:creator>LucD</dc:creator>
    <dc:date>2023-02-10T13:31:22Z</dc:date>
    <item>
      <title>Script to set disk ,CPU and Memory for an existing VMs</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Script-to-set-disk-CPU-and-Memory-for-an-existing-VMs/m-p/2953711#M110711</link>
      <description>&lt;P&gt;Hello VMWare Communities.&lt;/P&gt;&lt;P&gt;VMWare version : 7.x&lt;/P&gt;&lt;P&gt;I'm locking for a script to add or remove disk,memory and CPU on Multiples&amp;nbsp;existing VMs at ones.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Note&lt;/STRONG&gt; : Some of them the hot add feature is disabled and other is enabled.&lt;/P&gt;&lt;P&gt;Could you please help me&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 11:46:18 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Script-to-set-disk-CPU-and-Memory-for-an-existing-VMs/m-p/2953711#M110711</guid>
      <dc:creator>Jocker-H</dc:creator>
      <dc:date>2023-02-10T11:46:18Z</dc:date>
    </item>
    <item>
      <title>Re: Script to set disk ,CPU and Memory for an existing VMs</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Script-to-set-disk-CPU-and-Memory-for-an-existing-VMs/m-p/2953716#M110712</link>
      <description>&lt;P&gt;That is a very broad question.&lt;BR /&gt;The New-Harddisk (for harddisks) and Set-VM (for CPU and memory) cmdlets should do the trick.&lt;BR /&gt;Note that if you want to enable the hot-add feature, the VM will need to power off/power on.&lt;BR /&gt;&lt;BR /&gt;You will need to give more details.&lt;BR /&gt;Are the VMs that need changes in a list, a CSV perhaps?&lt;BR /&gt;Should the hot-add feature be enabled?&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 12:12:24 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Script-to-set-disk-CPU-and-Memory-for-an-existing-VMs/m-p/2953716#M110712</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2023-02-10T12:12:24Z</dc:date>
    </item>
    <item>
      <title>Re: Script to set disk ,CPU and Memory for an existing VMs</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Script-to-set-disk-CPU-and-Memory-for-an-existing-VMs/m-p/2953720#M110713</link>
      <description>&lt;P&gt;Hello LucD,&lt;/P&gt;&lt;P&gt;Yes the VM are in a list CSV that contain the VM name and the new value to be changed.&lt;/P&gt;&lt;P&gt;Some of them the Hot add Feature is disabled.&lt;/P&gt;&lt;P&gt;So i'm looking for a script to change the VM parameters disk, memory,CPU&amp;nbsp; if the Hot Add is enabled and if not return the list of the VM with disabled hot add option.&lt;/P&gt;&lt;P&gt;Every one how just started Learning Scripting could ask bad questions !&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 12:58:51 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Script-to-set-disk-CPU-and-Memory-for-an-existing-VMs/m-p/2953720#M110713</guid>
      <dc:creator>Jocker-H</dc:creator>
      <dc:date>2023-02-10T12:58:51Z</dc:date>
    </item>
    <item>
      <title>Re: Script to set disk ,CPU and Memory for an existing VMs</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Script-to-set-disk-CPU-and-Memory-for-an-existing-VMs/m-p/2953724#M110714</link>
      <description>&lt;P&gt;Try something like this.&lt;BR /&gt;&lt;BR /&gt;The new Harddisk is always applied.&lt;BR /&gt;&lt;BR /&gt;When the VM is powered off the CPU and Memory settings are always applied.&lt;BR /&gt;When the VM is powered on the hot-add and hot-remove settings are checked.&lt;BR /&gt;When a powered on VM doesn't have at least one of the required hot- settings it is exported to a CSV.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;# CSV layout: Name, CPU, Memory, Disk
#             VM1, 2, 4096, 40
#             VM2, 2, 4096, 40

$notEnabled = @()

Import-Csv -Path .\vm.csv -UseCulture -PipelineVariable row |
ForEach-Object -Process {
    $vm = Get-VM -Name $row.Name
    New-HardDisk -VM $vm -CapacityGB $row.Disk -Confirm:$false | Out-Null

    if($vm.PowerState -eq 'PoweredOn') {
        $cpuAdd = $cpuRemove = $memAdd = $true
        if($vm.CpuHotAddEnabled -and $row.CPU -gt $vm.NumCpu){
            Set-VM -VM $vm -NumCpu $row.CPU -Confirm:$false | Out-Null
        }
        else{
            $cpuAdd = $false
        }
        if($vm.CpuHotRemoveEnabled -and $row.CPU -lt $vm.NumCpu){
            Set-VM -VM $vm -NumCpu $row.CPU -Confirm:$false | Out-Null
        }
        else{
            $cpuRemove = $false
        }
        if($vm.MemoryHotAddEnabled -and $row.Memory -gt $vm.Memory){
            Set-VM -VM $vm -MemoryGB $row.Memory -Confirm:$false | Out-Null
        }
        else{
            $memAdd = $false
        }
    }
    else{
        Set-VM -VM $vm -NumCpu $row.CPU -MemoryGB $row.Memory -Confirm:$false | Out-Null
    }
    if($cpuAdd,$cpuRemove,$memAdd -notcontains $false){
        $notEnabled += New-Object -TypeName PSObject -Property ([ordered]@{
            VM = $vm.Name
            PowerState = $vm.PowerState
            CpuAdd = $cpuAdd
            CpuRemove = $cpuRemove
            MemAdd = $memAdd
        })
    }
}

$notEnabled | Export-Csv -Path .\notEnabled.csv -NoTypeInformation -UseCulture
&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 10 Feb 2023 13:31:22 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Script-to-set-disk-CPU-and-Memory-for-an-existing-VMs/m-p/2953724#M110714</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2023-02-10T13:31:22Z</dc:date>
    </item>
  </channel>
</rss>

