VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot

Unable to deploy template to particular datastore

Hi,

I am having issue deploying template to particular datastore. newly deployed VM doesnt get created in selected datastore,

please help!!

foreach ($item in $vmlist) {

Get-OSCustomizationSpec $item.Customization | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIp -IpAddress $item.IP_Address -SubnetMask $item.Subnet -DefaultGateway $item.Gateway -Dns $item.P_DNS,$item.S_DNS

New-VM -Name $item.VM_Name -Template $item.Template -Datastore $item.Datastore -VMHost $item.VMHost | Set-VM -OSCustomizationSpec $item.Customization -Confirm:$false

}

Reply
0 Kudos
15 Replies
LucD
Leadership
Leadership

You will have to provide a bit more information.
Are there any errors?
Are there events related to this VM creation?
What is in the $item variable?


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot

LucD,

there is no errors, VM gets deployed in the same datastore where template is currently located.

hereby attached the input file.

$vmlist = Import-CSV "D:\Jenkins\Scripts\deploytemplate\prod_vmdeploy.csv" -UseCulture

foreach ($item in $vmlist) {

#Configure the Customization Spec info

Get-OSCustomizationSpec $item.Customization | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIp -IpAddress $item.IP_Address -SubnetMask $item.Subnet -DefaultGateway $item.Gateway -Dns $item.P_DNS,$item.S_DNS

#Deploy the VM based on the template with the adjusted Customization Specification

New-VM -Name $item.VM_Name -Template $item.Template -Datastore $item.Datastore -VMHost $item.VMHost | Set-VM -OSCustomizationSpec $item.Customization -Confirm:$false

$VM | move-vm -InventoryLocation $(Get-Folder -Name $item.Folder -Location $(Get-Datacenter $item.Datacenter))

}

LucD, I think, this particular line $VM | move-vm -InventoryLocation $(Get-Folder -Name $item.Folder -Location $(Get-Datacenter $item.Datacenter)) is creating issue

Reply
0 Kudos
LucD
Leadership
Leadership

I just did some tests, and the clone process always placed the new VM on the datastore I passed on the Datastore parameter.
Could it be that you are targeting a cluster with fully automated DRS?

Or that the datastore is part of a DatastoreCluster with sDRS active?


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot

LucD,

DRS is manual and there is no Datastore cluster

I think, this particular line is creating issue, If I comment the below line, it works but by enabling this line, Datastore remains the same where the template resides.

$VM | move-vm -InventoryLocation $(Get-Folder -Name $item.Folder -Location $(Get-Datacenter $item.Datacenter))

I am using PowerCLI version

PS D:\myreports\Tools_Upgrade> Find-Module -Name VM*

Version              Name                                Repository           Description

-------              ----                                ----------           -----------

12.0.0.15939655      VMware.VimAutomation.Core           PSGallery            This Windows PowerShell module contains Windows PowerShell cmdlets for managing vSphere.

12.0.0.15939651      VMware.VimAutomation.Sdk            PSGallery            This Windows PowerShell module contains PowerCLI Sdk.

12.0.0.15939652      VMware.VimAutomation.Common         PSGallery            This Windows PowerShell module contains functionality required by multiple PowerCLI modules.

12.0.0.15939657      VMware.VimAutomation.Cis.Core       PSGallery            This Windows PowerShell module contains PowerCLI Cloud Infrastructure Suite cmdlets.

12.0.0.15940185      VMware.VimAutomation.Vds            PSGallery            This Windows PowerShell module contains PowerCLI VDS cmdlets.

7.0.0.15939650       VMware.Vim                          PSGallery            This Windows PowerShell module contains PowerCLI Vim.

12.0.0.15939670      VMware.VimAutomation.License        PSGallery            This Windows PowerShell module contains PowerCLI cmdlets for managing VMware product licenses.

12.0.0.15947286      VMware.PowerCLI                     PSGallery            This Windows PowerShell module contains VMware.PowerCLI

12.0.0.15947287      VMware.VimAutomation.Vmc            PSGallery            This Windows PowerShell module contains PowerCLI VMC cmdlets.

11.5.0.14899557      VMware.VimAutomation.Srm            PSGallery            This Windows PowerShell module contains PowerCLI SRM cmdlets.

12.0.0.15940184      VMware.VimAutomation.vROps          PSGallery            This Windows PowerShell module contains PowerCLI vROps cmdlets.

7.12.0.15718406      VMware.VimAutomation.HorizonView    PSGallery            This Windows PowerShell module contains Connect/Disconnect cmdlets for View API service.

12.0.0.15940183      VMware.VimAutomation.Cloud          PSGallery            This Windows PowerShell module contains PowerCLI Cloud cmdlets.

7.0.0.15902843       VMware.ImageBuilder                 PSGallery            This Windows PowerShell module contains PowerCLI ImageBuilder cmdlets.

12.0.0.15939671      VMware.VimAutomation.Nsxt           PSGallery            This Windows PowerShell module contains PowerCLI NSXT cmdlets.

12.0.0.15939648      VMware.VimAutomation.Storage        PSGallery            This Windows PowerShell module contains PowerCLI storage management cmdlets.

7.0.0.15902843       VMware.DeployAutomation             PSGallery            This Windows PowerShell module contains PowerCLI Auto Deploy cmdlets.

1.3.0.0              VMware.VimAutomation.StorageUtility PSGallery            This Windows PowerShell module contains utility scripts for storage.

6.5.1.7862888        VMware.VumAutomation                PSGallery            This Windows PowerShell module contains PowerCLI VUM cmdlets.

12.0.0.15939672      VMware.VimAutomation.Security       PSGallery            This Windows PowerShell module contains PowerCLI security management cmdlets.

12.0.0.15939647      VMware.VimAutomation.Hcx            PSGallery            This Windows PowerShell module contains PowerCLI HCX cmdlets.

6.5.4.7567193        VMware.VimAutomation.HA             PSGallery            This Windows PowerShell module contains PowerCLI HA cmdlets.

10.0.0.7893924       VMware.VimAutomation.PCloud         PSGallery            This Windows PowerShell module contains PowerCLI vCloud Air cmdlets.

12.0.0.15947289      VMware.CloudServices                PSGallery            PowerCLI CloudServices sample module.

12.0.0.15947288      VMware.VimAutomation.WorkloadMan... PSGallery            PowerShell commands for automation of workloads related functionality in vSphere.

Reply
0 Kudos
LucD
Leadership
Leadership

That looks very strange.
That line moves the VM to a Folder of type VM and Template and has nothing to with svMotion.

But that means that the New-VM cmdlet with the Datastore is working as expected.

So no problem in New-VM it seems.

Since DRS is set to Manual,  I don't assume there is any trace of the VM being moved in the History?

Any events concerning this VM?


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot

LucD,

Move-VM command is moving the VM to folder along with storage vMotion

pastedImage_0.png

Reply
0 Kudos
LucD
Leadership
Leadership

That Move-VM line you gave is never initiating an svMotion.
Can you check via the events what could be triggering that svMotion?

Let's start with exploring these events (run within 5 minutes after the New-VM)

$event = Get-VIEvent -Start (Get-Date).AddMinutes(-5) -MaxSamples ([int]::MaxValue)

$event | Group-Object -Property {$_.GetType().Name}

$event | where{$_.FullFormattedMessage -match 'Relocating'}


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot

LucD,

Please find the output

DestHost         : VMware.Vim.HostEventArgument
DestDatacenter   : VMware.Vim.DatacenterEventArgument
DestDatastore    : VMware.Vim.DatastoreEventArgument
Template         : False
Key              : 6841760
ChainId          : 6841759
CreatedTime      : 04/27/2020 8:37:14 AM
UserName         : domain\adm.mamo
Datacenter       : VMware.Vim.DatacenterEventArgument
ComputeResource  : VMware.Vim.ComputeResourceEventArgument
Host             : VMware.Vim.HostEventArgument
Vm               : VMware.Vim.VmEventArgument
Ds               : VMware.Vim.DatastoreEventArgument
Net              :
Dvs              :

FullFormattedMessage : Relocating deploytest678 in RCH from 10.10.10.118, Shared_Vol_1 to 10.10.10.118, DS_ISO_Vol

ChangeTag        :
Reply
0 Kudos
LucD
Leadership
Leadership

You might want to edit that output, I suspect there is some personal info in there.f

The overview of the types of events is missing.
I'm curious if there is a DRS event in there.

Also the details of that TaskEvent that seems to have triggered it all would be interesting.

Especially the Info part.

$t = $event | where{$_ -is [VMware.Vim.TaskEvent]}

$t

$t.Info


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot

Please find the requested ouput.

Reply
0 Kudos
LucD
Leadership
Leadership

From the information I have seen, it looks as if SRM is involved.

Could it be that you are trying to place a protected VM on a non-protected datastore?


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot

Yes LucD, we do have SRM in our environment but we are creating a new VM from a template where that it is currently placed in a datastore that is not part of SRM

This script was working fine till I upgraded my PowerCLI to latest version

Reply
0 Kudos
LucD
Leadership
Leadership

Like I said earlier, I can't reproduce that behavior.

I suggest you open an SR.


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot

LucD,

Where can I submit a request for PowerCLI issue from VMware Support site ?

Reply
0 Kudos
LucD
Leadership
Leadership

The normal way you contact GSS.
If in doubt, contact your TAM.

GSS will probably say that you need a Developer Support contract, but in that case, point them to PowerCLI Support Breakdown especially para 3 & 4.


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

Reply
0 Kudos