I'm working on user powercli to modify the CPU and Memory of multiple VMs.
I found the perfect script created: http://ict-freak.nl/2010/05/07/powercli-script-to-schedule-memory-and-or-vcpu-updowngrade/comment-pa...
But it's only for 1 VM.
Can anyone tell me to modify it so do multiple VMs. A text file would be ideal, but i'm up for anything that this point, nothing I try is working.
Thanks.
You could do
foreach($vm in Get-VM -Name (Get-Content C:\Powercli_scripts\servers.txt))
I'm not sure why it's doing random poweroffs.
You could add the -WhatIf parameter on that line, that way it will only say what it's doing, without actually executing the cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
A few small changes to the Main part of Arne's script should allow this.
Try something like this
....
####################################################################################### # Main script ####################################################################################### $VIServer = Connect-VIServer $vCenter
If ($VIServer.IsConnected -ne $true){ Write-Host "error connecting to $vCenter" -ForegroundColor Red
exit
} foreach($vm in Get-VM){ if($MemoryMB -or $CPUCount -ne "0"){ $poweroff = PowerOff-VM $vm.Name
if($poweroff -eq "Ok"){ Write-Host "PowerOff OK" if($MemoryMB -ne "0"){ if($MemoryOption -eq " ") {Write-Host "Please enter an option to add or remove memory"} else{ Change-VMMemory $vm.Name $MemoryMB $MemoryOption
} } if($CPUCount -ne "0"){ if($CPUOption -eq " ") {Write-Host "Please enter an option to add or remove cpu"} else{ Change-VMCPUCount $vm.Name $CPUCount $CPUOption
} } $poweron = PowerOn-VM $vm.Name
if($poweron -eq "Ok"){ Write-Host "PowerOn OK"} } } }
Note: the functions part of the script stays the same, just replace the "Main" part
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Oh man, getting so close.
For some reason it's powering off random servers.
Can I do something like this and pull from a text file: foreach($vm in C:\Powercli_scripts\servers.txt)
Or in the script:
You could do
foreach($vm in Get-VM -Name (Get-Content C:\Powercli_scripts\servers.txt))
I'm not sure why it's doing random poweroffs.
You could add the -WhatIf parameter on that line, that way it will only say what it's doing, without actually executing the cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That was it man.
I had to update it a little, but that was it: foreach($vm in Get-VM -Name (Get-Content .\servers.txt)
Hello - I would i invoke the script not to specify one vm?
.\Change-VM_Memory_CPU_Count.ps1 -vCenter we-vctsrv-02 -vmName <> -MemoryMB 2048 -MemoryOption Add -CPUCount 1 -CPUOption Add
