VMware Cloud Community
zenivox
Hot Shot
Hot Shot
Jump to solution

new-vm the operation is not supported on the object

Hello I have script that automates the creation of multiple VMs using  a csv file. The first VM is created successfully but when the loop goes for the second VM I get:

zenivox_0-1605635026701.png

it's a lab with single ESXi host no vCluster but it's licensed with Enter Plus. I'm connected to vCenter server. This is the PowerCLI installed:

zenivox_1-1605635114513.png

Anybody got the same problem?

 

Reply
0 Kudos
1 Solution

Accepted Solutions
zenivox
Hot Shot
Hot Shot
Jump to solution

installed fresh PowerCLI on a VM and it worked! I then updated the modules on my laptop and also there it worked!

View solution in original post

Reply
0 Kudos
8 Replies
zenivox
Hot Shot
Hot Shot
Jump to solution

I have the feeling I have to update the powercli modue.. but I'll go for it if "really" necessary...

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Is that the same script from your other thread?
The error seems to be for the Template, not the VM.
Or do you have that name also in the CSV?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
zenivox
Hot Shot
Hot Shot
Jump to solution

yes, it is the same.. here below. The template is declared at the beginning of the script.. outside the loop.. and it works for the first VM

# Necessary to import the AD browser module
Import-Module .\Choose-ADOrganizationalUnit.ps1
Import-Module ActiveDirectory

$conn = Read-Host "Do you want to connect to the vCenter server? [Y/N]"
if($conn.ToUpper() -eq "Y") {
$creds = Get-Credential
Connect-VIServer "vimwfpromsbvc.global.wfp.org" -Credential $creds
}

$csv = import-csv .\New_VMs.csv
$Template = 'TPL-TEST'
$vmhost = "10.11.30.39"


# Choose a Datastore to deploy to
$Datastores = Get-VMHost $vmhost | Get-Datastore | Select-Object Name | Sort-Object Name
$i = 1
$Datastores | ForEach-Object{Write-Host $i":" $_.Name; $i++}
$DSIndex = Read-Host "Enter a number ( 1 -" $Datastores.count ")"
$SDatastore = $Datastores[$DSIndex - 1].Name
Write-Host "You have selected the $SDatastore datastore" -ForegroundColor Green
Start-Sleep -Seconds 2

# Folder Selection
Write-Host "Select which folder to place the VM in"
$IFOLDER = Get-Folder | Select-Object Name | Sort-Object Name
$i = 1
$IFOLDER | ForEach-Object{Write-Host $i":" $_.Name; $i++}
$FSIndex = Read-Host "Select a Folder. Enter a number ( 1 -" $IFOLDER.Count ")"
$SFOLDER = $IFOLDER[$FSIndex - 1].Name
write-host "."
write-host "You picked the $SFOLDER folder" -ForegroundColor Green
Start-Sleep -Seconds 2

# Read Name, Network, vLAN ID from CSV
foreach($Row in $csv) {

# create AD computer object in right OU in AD
$OU = Choose-ADOrganizationalUnit
New-ADComputer -Name $Row.Name -SamAccountName $Row.Name -Path $OU.DistinguishedName

# You can also change -template to -contentlibraryitem
#$vmhost = Get-Cluster $SCluster | Get-VMHost | Select-Object -First 1

## Create Customisation
if (!(Get-OSCustomizationSpec -Name "TMP")){
Get-OSCustomizationSpec -Name "STATIC-IP-csv" | New-OSCustomizationSpec -Name "TMP" -Type NonPersistent
}
## Set Network Properties
$IP = @{OScustomizationNicMapping = Get-OSCustomizationNicMapping -OSCustomizationSpec "TMP"}
$IP.IPMode = "UseStaticIP"
$IP.IPAddress = $Row.IP
$IP.SubnetMask = $Row.SN
$IP.DefaultGateway = $Row.GW
$IP.dns = $Row.DNS1,$Row.DNS2
Set-OSCustomizationNicMapping @ip

## Deploy VM
New-VM -Name $Row.Name -Template $Template `
-VMHost $vmhost `
-Datastore $SDatastore `
-Location $SFOLDER `
-OSCustomizationSpec "TMP" `
-ErrorAction Stop

## Power UP VM to complete customisation
Start-VM $Row.Name
Wait-Tools -VM $Row.Name
$myVDPortGroup = Get-VDPortgroup | Where-Object{$_.VlanConfiguration -match "VLAN $($Row.vlan)"}
Get-VM -Name $Row.Name | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName $myVDPortGroup.Name -Connected:$true -Confirm:$false

}

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Since you are connected to an ESXi and not a vCenter, how can you in fact use a Template?
That is a function that comes with vCenter afaik.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
zenivox
Hot Shot
Hot Shot
Jump to solution

I've already read the other posts about it but I don't think the video ram thing matches my situation. Unfortunately I run my scripts on my laptop and I'm afraid of screwing the PS/PowerCLI binomy on it... I'll install latest powercli on a VM and try...

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

???
A newer PowerCLI version will not solve the fact that a Template is a vCenter feature


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
zenivox
Hot Shot
Hot Shot
Jump to solution

thanks as usual Luc... as stated I'm connected to vcenter server... it's just that the ESXi is a single host.. but licensed

Reply
0 Kudos
zenivox
Hot Shot
Hot Shot
Jump to solution

installed fresh PowerCLI on a VM and it worked! I then updated the modules on my laptop and also there it worked!

Reply
0 Kudos