Quantcast
Channel: VMware Communities : Discussion List - All Communities
Viewing all articles
Browse latest Browse all 176483

VM Deployment with customization, parallel

$
0
0

All,

  I am using a modified script I found on Jase's blog, (Thanks!) and it appears to be working great, but my big problem is it does one at a time.  I would like them to go in parallel. Is there anyway to do this?  I have tried to add the -RunAsync option on my new-vm command, but then I get errors. Without the runasync command it works group see errors below the script.

 

##########################################################
# cloneandsetip.ps1

 

##########################################################
Connect-VIServer vcentername.name.com

$vmlist = Import-CSV vms.csv

foreach ($item in $vmlist) {

    # I like to map out my variables
    $basevm = $item.basevm
    $datastore = $item.datastore
    $vmhost = $item.vmhost
    $custspec = $item.custspec
    $vmname = $item.vmname
    $ipaddr = $item.ipaddress
    $subnet = $item.subnet
    $gateway = $item.gateway
    $pdns = $item.pdns
    $sdns = $item.sdns
    $vlan = $item.vlan

    #Get the Specification and set the Nic Mapping
    Get-OSCustomizationSpec $custspec | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIp -IpAddress $ipaddr -SubnetMask $subnet -DefaultGateway $gateway -Dns $pdns,$sdns
   
    #Clone the BaseVM with the adjusted Customization Specification
   New-VM -Name $vmname -template $basevm -Datastore $datastore -VMHost $vmhost -RunAsync | Set-VM -OSCustomizationSpec $custspec -Confirm:$false

    #Set the Network Name (I often match PortGroup names with the VLAN name)
    Get-VM -Name $vmname | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName $vlan -Confirm:$false

    #Remove the NicMapping (Don't like to leave things unkept)
    Remove-OSCustomizationNicMapping -OSCustomizationNicMapping (Get-OSCustomizationSpec Test | Get-OSCustomizationNicMapping) -Confirm:$false

 

 

 

 

 

Errors that occur:

 

Set-VM : The input object cannot be bound to any parameters for the command eit
her because the command does not take pipeline input or the input and its prope
rties do not match any of the parameters that take pipeline input.
At U:\powercli\deployvm.ps1:30 char:100
+     New-VM -Name $vmname -template $basevm -Datastore $datastore -VMHost $vmh
ost -RunAsync | Set-VM <<<<  -OSCustomizationSpec $custspec -Confirm:$false
    + CategoryInfo          : InvalidArgument: (CloneVM_Task:PSObject) [Set-VM
   ], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectNotBound,VMware.VimAutomation.ViCore.
   Cmdlets.Commands.SetVM

 

Get-OSCustomizationSpec : 2/17/2012 12:59:16 PM    Get-OSCustomizationSpec
   Could not find Customization Specification with name 'Test'.
At U:\powercli\deployvm.ps1:36 char:89
+     Remove-OSCustomizationNicMapping -OSCustomizationNicMapping (Get-OSCustom
izationSpec <<<<  Test | Get-OSCustomizationNicMapping) -Confirm:$false
    + CategoryInfo          : ObjectNotFound: (Test:String) [Get-OSCustomizati
   onSpec], VimException
    + FullyQualifiedErrorId : Common_CommonUtil_FilterCollection_ObjectNotFoun
   d,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetOSCustomizationSpec

 

Remove-OSCustomizationNicMapping : Cannot bind argument to parameter 'OSCustomi
zationNicMapping' because it is null.
At U:\powercli\deployvm.ps1:36 char:64
+     Remove-OSCustomizationNicMapping -OSCustomizationNicMapping <<<<  (Get-OS
CustomizationSpec Test | Get-OSCustomizationNicMapping) -Confirm:$false
    + CategoryInfo          : InvalidData: (:) [Remove-OSCustomizationNicMappi
   ng], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,V


Viewing all articles
Browse latest Browse all 176483

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>