Quantcast
Channel: VMware Communities : All Content - VMware PowerCLI
Viewing all articles
Browse latest Browse all 16717
↧

New-VM from Template

$
0
0

Hey all,

 

It's been a while but I'm running into something I'd like another set of eyes on.  I'm running the below script and it executes fine and does what I want but it spits out a lot of errors in the process.  I wanted to clean up some of the errors.  Also, I'm sure there's a much better way to do this, I just reused some old parts I already had.

 

New-VM : 5/18/2018 8:53:04 AM   New-VM          Operation is not valid due to the current state of the object.

At C:\\PowerCLI\batch_VM_Multi.ps1:25 char:13

+ $vmNewOne = New-VM  -Name tarheels-test-$_ @hshNewVMParams

+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [New-VM], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM

 

 

Get-NetworkAdapter : Cannot validate argument on parameter 'Snapshot'. The argument is null. Provide a valid value for

the argument, and then try running the command again.

At C:\PowerCLI\batch_VM_Multi.ps1:27 char:13

+ $vmNewOne | Get-NetworkAdapter | Set-NetworkAdapter -PortGroup $oSome ...

+             ~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidData: (:) [Get-NetworkAdapter], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDev

   ice.GetNetworkAdapter

 

 

## Name of Template

$strSourceTemplate = "W2K12R2-STD-Template"

 

## Destination Cluster

$strSomeCluster = "Court-Side"

 

## Destination Datastore Cluster

$strDestDStore = "ds-02"

 

## PortGroup

$strSomePG = "customer-data-201"

$oSomePG = Get-VirtualPortGroup -Name $strSomePG

 

## Hash Table of Values for for New VM Creation

$hshNewVMParams = @{

    Template = $strSourceTemplate

## default "Resources" resource pool, so as to put VM in desired cluster

    ResourcePool = Get-Cluster $strSomeCluster | Get-ResourcePool -Name "Resources"

Datastore = Get-Datastore -Name $strDestDStore

}

## End Hash Table

 

1..20 | Foreach {

## Create VM

$vmNewOne = New-VM  -Name tarheels-test-$_ @hshNewVMParams

## Set PortGroup and MAC Address

$vmNewOne | Get-NetworkAdapter | Set-NetworkAdapter -PortGroup $oSomePG -RunAsync

}

 

1..20 | Foreach {

## Power on each VM

Start-VM -VM tarheels-test-$_

}

↧

Viewing all articles
Browse latest Browse all 16717


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