Solved

powershell Scripting - powercli for vmware

Posted on 2015-01-28
4
205 Views
Last Modified: 2015-02-11
Hi Guys,

I have run this script and for some reason it added the harddisks quite a few times, please can somone point out what i am doing wrong here.

thank you in advance.

$vm="DEV-FIN-APP-01","DEV-FIN-WEB-01","DEV-SQL-FIN-01","DEV-RDS-FIN-01"

$vm | % { 

    If ($_="DEV-FIN-APP-01")

        {
        
        Set-VM -VM $_ -NumCpu 4 -MemoryGB 8 -Notes "Request 55274 " -Confirm:$false
        New-HardDisk -VM $_ -CapacityGB 50 -ThinProvisioned:$false -Confirm:$false
        New-HardDisk -VM $_ -CapacityGB 100 -ThinProvisioned:$false -Confirm:$false

        }


    if ($_="DEV-FIN-WEB-01")
        {

        Set-VM -VM $_ -NumCpu 2 -MemoryGB 4 -Notes "Request 55274 " -Confirm:$false
        New-HardDisk -VM $_ -CapacityGB 50 -ThinProvisioned:$false -Confirm:$false
       

        }

   

     if ($_="DEV-SQL-FIN-01")
        {

        Set-VM -VM $_ -NumCpu 4 -MemoryGB 16 -Notes "Request 55274 " -Confirm:$false
        New-HardDisk -VM $_ -CapacityGB 50 -ThinProvisioned:$false -Confirm:$false
        New-HardDisk -VM $_ -CapacityGB 50 -ThinProvisioned:$false -Confirm:$false
        New-HardDisk -VM $_ -CapacityGB 300 -ThinProvisioned:$false -Confirm:$false
        New-HardDisk -VM $_ -CapacityGB 150 -ThinProvisioned:$false -Confirm:$false
        New-HardDisk -VM $_ -CapacityGB 300 -ThinProvisioned:$false -Confirm:$false
        New-HardDisk -VM $_ -CapacityGB 150 -ThinProvisioned:$false -Confirm:$false
        New-HardDisk -VM $_ -CapacityGB 75 -ThinProvisioned:$false -Confirm:$false
        New-HardDisk -VM $_ -CapacityGB 300 -ThinProvisioned:$false -Confirm:$false
        New-HardDisk -VM $_ -CapacityGB 150 -ThinProvisioned:$false -Confirm:$false

        }

      if ($_="DEV-RDS-FIN-01")

        {

        Set-VM -VM $_ -NumCpu 2 -MemoryGB 8 -Notes "Request 55274 " -Confirm:$false
        New-HardDisk -VM $_ -CapacityGB 50 -ThinProvisioned:$false -Confirm:$false
 
        }



	#Get-VM $_ | get-networkadapter | set-networkadapter -networkname "LND_WEB_2264" -Confirm:$false#

	#Enable copy and paste

	Get-vm $_ | New-AdvancedSetting -Name isolation.tools.copy.disable -Value FALSE -Confirm:$false -Force:$true

	Get-vm $_ | New-AdvancedSetting -Name isolation.tools.paste.disable -Value FALSE -Confirm:$false -Force:$true


}

Open in new window

0
Comment
Question by:Kay
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Author Comment

by:Kay
ID: 40575212
I also got this error on the powershell screen:

DEV-RDS-FIN-01       PoweredOff 2        8.000          
New-HardDisk : 28/01/2015 14:15:43    New-HardDisk        Operation is not valid due to the current state of the object.    
At line:46 char:9
+         New-HardDisk -VM $_ -CapacityGB 50 -ThinProvisioned:$false -Confirm:$fal ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-HardDisk], VimException
    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.NewHardDisk
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 40575286
Would this work for you?  There seems to be some repetition in the 3rd vm...
$vm1=@{ name = 'DEV-FIN-APP-01'; cpu=4; mem=8; notes='Request 55274 ';drv=@(50,100)}
$vm2=@{ name = 'DEV-FIN-WEB-01'; cpu=2; mem=4; notes='Request 55274 ';drv=@(50)}
$vm3=@{ name = 'DEV-SQL-FIN-01'; cpu=4;mem=16;notes='Request 55274 ';drv=@(50,50,300,150,300,150,75,300,150)}
$vm4=@{ name = 'DEV-RDS-FIN-01'; cpu=2;mem=8;notes='Request 55274 ';drv=@(50)}
$vms = $vm1,$vm2,$vm3,$vm4

foreach ($vm in $vms) {
    set-vm -vm $vm.name -numcpu $vm.cpu -memoryGB $vm.mem -Notes $vm.notes -confirm:$false
    foreach ($size in $vm.drv) {
        new-harddisk -vm $vm.name -capacityGB $size -ThinProvisioned:$false -Confirm:$false
    }

}

Open in new window

0
 
LVL 40

Accepted Solution

by:
footech earned 500 total points
ID: 40575787
In your original script, the If conditions are using "=" when you should use "-eq".
If ($_="DEV-FIN-APP-01")
should be
If ($_ -eq "DEV-FIN-APP-01")
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 40591944
How are you making out?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
Giving access to ESXi shell console is always an issue for IT departments to other Teams, or Projects. We need to find a way so that teams can use ESXTOP for their POCs, or tests without giving them the access to ESXi host shell console with a root …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question