VMware Cloud Community
Zeesyed
Contributor
Contributor

Add sockets using script.

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.

0 Kudos
10 Replies
RvdNieuwendijk
Leadership
Leadership

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
}

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
Zeesyed
Contributor
Contributor

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

0 Kudos
Troy_Clavell
Immortal
Immortal

did you connect to vCenter or ESX first?

Connect-VIServer


0 Kudos
RvdNieuwendijk
Leadership
Leadership

Something went wrong with copying and pasting the script. Your first line is different than mine. Smiley Wink

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
Zeesyed
Contributor
Contributor

Attached is the script along with vms.txt for server names. Please check I am not sure what is that I am doing wrong.

Yes I am already logged into virtual center through vi Client and as well as through powercli.

0 Kudos
Troy_Clavell
Immortal
Immortal

I don't want to speak on behalf of Robert because he does have the correct code, but i'm just adding my .02 in case he's out of pocket.

Try

Get-Content C:\VMs.txt |
ForEach-Object {
  Get-VM -Name $_ |
  Set-VM -NumCPU 4 -Confirm:$false
}

0 Kudos
RvdNieuwendijk
Leadership
Leadership

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.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
Zeesyed
Contributor
Contributor

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.

0 Kudos
Troy_Clavell
Immortal
Immortal

that will work.

0 Kudos
Zeesyed
Contributor
Contributor

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.

0 Kudos