VMware Cloud Community
drwoodberry
Contributor
Contributor
Jump to solution

New-VM -diskpath

I am trying to create a bunch of VM's from a csv file. I can easily create the VM's with the help of some code I found on here. I am now trying to create a new-vm from a CSV but this time I am trying to use an exsisting vmdk that I have on one of the datastores. The datastore is shared storage. I am trying to figure out what path to give the script. Any help would be great.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

To create new guests with an existing .vmdk (or hard disk) you can use

New-VM -Name "NewGuest" -DiskPath "[dsname] Folder/Filename.vmdk" -VMHost (Get-VMHost esxhostname)

Watch out ! There has to be only 1 blank between the closing square bracket and the foldername !

You can add additional parameters to the New-VM cmdlet depending on the specifics of the guest you are creating.

____________

Blog: LucD notes

Twitter: lucd22


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

View solution in original post

0 Kudos
5 Replies
Dave_Mishchenko
Immortal
Immortal
Jump to solution

You can specify the datastore path like this.

 Get-VM CLUSTER03 | New-HardDisk -DiskPath "[ESX01_local]  CLUSTER_SHARED/TEST.vmdk 






Dave

VMware Communities User Moderator

Now available - vSphere Quick Start Guide

Do you have a system or PCI card working with VMDirectPath? Submit your specs to the Unofficial VMDirectPath HCL.

0 Kudos
drwoodberry
Contributor
Contributor
Jump to solution

I don't think I follow. Is this to attach to an existing vmdk

0 Kudos
LucD
Leadership
Leadership
Jump to solution

To create new guests with an existing .vmdk (or hard disk) you can use

New-VM -Name "NewGuest" -DiskPath "[dsname] Folder/Filename.vmdk" -VMHost (Get-VMHost esxhostname)

Watch out ! There has to be only 1 blank between the closing square bracket and the foldername !

You can add additional parameters to the New-VM cmdlet depending on the specifics of the guest you are creating.

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
drwoodberry
Contributor
Contributor
Jump to solution

Thanks again! In my script I put the disk path location as you have it, but I did not put quotes around it. Should I have to do that? When I enter everything like you did, it works. My csv file looks like this:

 
Name,NumCPU,DiskMB,MemoryMB,GuestID,Datastore,DiskPath
CPoF Backup 2,1,40960,4096,winNetEnterpriseGuest,ds2,[ds1] CPOFBACKUP2/ntrevcry.vmdk

and when being run from the csv I get this:

The disk path "[ds1] CPOFBACKUP2/ntrecvry.vmdk" is invalid

If I use your code with my location I have no issues...does the CSV require quotes around it?

0 Kudos
drwoodberry
Contributor
Contributor
Jump to solution

LucD,

Thanks for your help. I have it working now. Please ignore my above post because I had a typo in my syntax. When I attach to this existing disk, the .VMX, .VMXF and .VMSD files are created in another folder on the datastore I specify. Is there an easy way to get these files to be created in the same folder as the .VMDK file? Ultimately they are all apart of the same machine and would like them stored together.

0 Kudos