Solved

powershell Scripting - powercli for vmware

Posted on 2015-01-28
4
135 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
Comment Utility
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
Comment Utility
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 39

Accepted Solution

by:
footech earned 500 total points
Comment Utility
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
Comment Utility
How are you making out?
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Will try to explain how to use the VMware feature TAGs in the VMs and create Veeam Backup Jobs using TAGs. Since this article is too long, I will create second article for the Veeam tasks.
HOW TO: Connect to the VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere (HTML5 Web) Host Client 6.5, and perform a simple configuration task of adding a new VMFS 6 datastore.
Teach the user how to install log collectors and how to configure ESXi 5.5 for remote logging Open console session and mount vCenter Server installer: Install vSphere Core Dump Collector: Install vSphere Syslog Collector: Open vSphere Client: Config…
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now