I’m trying to add 2 sockets to the group of servers in my company. Currently we have 2 Sockets my goal it to bump it up to 4 sockets. I would like to create a script (powercli or anything) to perform this task, where script should read from a text file (list of VMs) and perform this task. Any help will be greatly appreciated.
If you create a text file called 'VMs.txt' that contains the name of a virtual machine on every line, then you can use the next PowerCLI script to change the number of virtual CPU's for those VM's to 4.
Get-Content -Path VMs.txt | ForEach-Object { Get-VM -Name $_ | Set-VM -NumCPU 4 -Confirm:$false }
I saved my file on c:\VMs.txt I ran the following command using Powercli, it is asking for a password. Also I tried to save the following file as test.ps1 after executing it is asking for a password....
Get-Content -c:\VMs.txt VMs.txt | ForEach-Object {
Get-VM -Name $_ |
Set-VM -NumCPU 4 -Confirm:$false
}
I am getting the following error when I run from Powercli window.
The provider does not support the use of credentials. Perform the operation aga
in without specifying credentials.
At line:1 char:1
+ <<<< Get-Content -c:\VMs.txt | ForEach-Object {Get-vm -name $_ | set-vm -num
cpu 4 -confirm:$false }
+ CategoryInfo : NotImplemented: (:) [], PSNotSupportedException
+ FullyQualifiedErrorId : NotSupported
did you connect to vCenter or ESX first?
Connect-VIServer
Something went wrong with copying and pasting the script. Your first line is different than mine.
Troy's version will work also. With the copying and pasting of the script you inserted -c:\vms.txt in the first line that should be removed or replaced by -Path.
Sorry to bother you guys...
Is this correct?
Get-Content -Path c:\VMs.txt |
ForEach-Object {
Get-VM -Name $_ |
Set-VM -NumCPU 4 -Confirm:$false
}
Above has been saved as test.ps1 on my C drive with the text file vms.txt with one server name "zeewindow". I already powered down the server because hot add is not supported.
that will work.
It worked this morning, I appreciate your help. Thank you!
However it doesn’t work when I trigger the script from the location on my computer. Instead I have to copy and past the same script to the powerCLI window and execute for it to work.
Any suggestions on that will be greatly appreciated.