Solved

powershell Scripting - powercli for vmware

Posted on 2015-01-28
4
185 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
  • 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

In this article, I show you step by step with screenshots to assist you - HOW TO: Deploy and Install the VMware vCenter Server Appliance 6.5 (VCSA 6.5), with some helpful tips along the way.
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).
Teach the user how to join ESXi hosts to Active Directory domains Open vSphere Client: Join ESXi host to AD domain: Verify ESXi computer account in AD: Configure permissions for domain user in ESXi: Test domain user login to ESXi host:
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

840 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