Solved

powershell Scripting - powercli for vmware

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

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).
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This Micro Tutorial walks you through using a remote console to access a server and install ESXi 5.1. This example is showing remote access and installation using a Dell server. The hypervisor is the very first component of your virtual infrastructu…

635 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