Create new virtual machine of the model that have two hard drives in the different data store

We do VM deploy automation with PowerCLI.

There is already a model created with at least two hard drives to one side and each hard drive belong to difference datastore,

In the model's operating system is Windows server 2008 R2 already installed VMware Tools and other software in the second (other than C: driver) driver

We can successfully deploy a new virtual machine with this manually with vSphere client model.

But when we try to make the deployment with PowerCLI, can not find examples of similar scripts in the document of reference,

and we also google this question, still no similar question was found.

Is this possible with PowerCLI? If it's possible could you give me some advice or an example of script, thank you!

Best regards.

I already found the solution.

With the vSphere SDK .NET API, we can create the new virtual machine to the model

Mainly used API listed below, sorry because I can not give the source code here.

  • VMware.Vim.VirtualMachineCloneSpec
  • VMware.Vim.VirtualMachineRelocateSpec
  • VMware.Vim.ManagedObjectReference
  • VMware.Vim.VirtualMachineRelocateSpecDiskLocator
  • VMware.Vim.ManagedObjectReference
  • CloneVM_Task

For reference, you can take a look at this post and this post

LucD , thanks for your help!

Tags: VMware

Similar Questions

  • Clone the virtual machine to the local data store

    Hi all

    I'm looking to automate a task daily (or almost) of my friends with a small script with powercli.

    I'm trying to "backup" or to clone a virtual machine, I work in a storage of one of our servers.

    The servers are managed by a 5.1 vCenter and the machine is on a shared storage.

    From time to time, I clean, stop the machine, remove all snapshots and clone the virtual machine to one of the local server as a backup storage. So I put together a small script which almost works. It works as long as the target data store is a shared storage, but not with a local storage.

    I get always an error that claims it can not access the local data store and is not a permissions problem...

    Given that I can accomplish this via the customer without problem I thought it is possible via powercli too, or I'm wrong?

    My Script up to now:

    # Variables
    $VC = "vc.domain.com" #vCenter Server
    $User = "domain\user" #User
    $Pass = 'test123' #User PW
    $VMName = 'scripttest' #VM
    $BackupSuffix = "backup" #Suffix to add the name of VM to mark this as a backup
    $VmHost = "esx2.domain.com".
    $Datastore = 'ESX2-LocalData' #Datastore
    $BackupFolder = 'Backup' #Folder the VM gets classified


    # Register cmdlets to VMware

    If (-not (Get-PSSnapin VMware.VimAutomation.Core - ErrorAction SilentlyContinue)) {}

    Add-PSSnapin VMware.VimAutomation.Core

    }


    # Connect to the server

    SE connect-ViServer $VC - user $User-password $Pass


    # Remove the old clone

    $OldBackups = get - VM | WHERE {$_.} {Name: corresponds to '$VMName - $BackupSuffix'}

    If ($OldBackups - don't "")

    {

    If ($OldBackups.Count - gt 1)

    {

    Write-Host "better check! "Found several results:

    Foreach ($VM to $OldBackups)

    {

    Write-Host $VM. Name

    }

    }

    on the other

    {

    Remove-VM - VM $OldBackups - DeleteFromDisk-confirm: $false

    }

    }


    # Clone VM

    $VMInfo = get - VM $VMName | Get-View

    $CloneSpec = new-Object Vmware.Vim.VirtualMachineCloneSpec

    $CloneSpec.Snapshot = $VMInfo.Snapshot.CurrentSnaphshot

    $CloneSpec.Location = new-Object Vmware.Vim.VirtualMachineRelocateSpec

    $CloneSpec.Location.Datastore = (get-Datastore-name $Datastore |) Get - View). MoRef

    $CloneSpec.Location.Transform = [Vmware.Vim.VirtualMachineRelocateTransformation]: sparse

    $CloneFolder = $VMInfo.Parent

    $CloneName = "$VMName - $BackupSuffix".

    $TaskCloneID = $VMInfo.CloneVM_Task ($CloneFolder, $CloneName, $CloneSpec)


    # Check if the task is completed


    $Check = $false

    While ($Check - eq $false)

    {

    $Tasks = get-job | Select State, id | Where {$_.} State - eq "Running" - and $_. State - eq "pending"}

    ForEach ($Task in $Tasks)

    {

    If ($Task.id - eq $TaskCloneID)

    {$Check = $false}

    on the other

    {$Check = $true}

    }

    Start-Sleep 10

    }

    # Move clone to the backup folder

    Move-VM - VM '$VMName - $BackupSuffix' - Destination $BackupFolder


    # Disconnect

    Disconnect-VIServer-confirm: $false

    Can you show us the complete error message you get?

    BTW, the clone step can be replaced by the New-VM cmdlet with the setting of the virtual machine.

  • Size of the virtual machines on the local data store

    What is the best way to determne the (total) disk space using a virtual machine? We have several virtual machines on local data warehouses and would like to estimate roughly how much disk space to the total number of virtual machines use to caculate how much storage SAN, they will consume. Is there an 'easy' way to socket this information?

    The most accurate way would be to calculate the total space used by the virtual machine files in the data store.

    Connect to the service console

    Navigate to the vmfs volume

    Navigate to the vm folder

    -h.

    This will give you files for this particular virtual machine related to the amount of disk space used by all the vm

    Méhul

  • PowerCLI script - new virtual machine of the model

    Hi all

    I am very new to power CLI scripting, and these days, that I read a lot of help to automate the creation of a new virtual machine based on the model of the virtual machine.  Script that is not that hard, even location new virtual machine on a particular data and in a particular resource pool store is not difficult.  For this I came up with this very basic script/command:

    "New-VM - ResourcePool < resource_pool > - < folder_name > location - Datastore < datastore_name > - name < VM_name > - < template_name >"model

    However, I came across some problems that I can't find information in help or in the forums.  Problem with the above command is VM will be created in the pool of appropriate resources and file as long as they are unique, but if there are multiple instances of resource pool or a folder with the same name as the script spits out a mannequin.

    So for example if I want to create a new virtual machine to the location following Data_Centre = > RootFolder1 = > SubFolder1 = > SubFolder2 and SubFolder2 name is unique that no problem, the virtual machine is created at this location.  However, if the SubFolder2 exists in Data_Centre = > RootFolder2 = > SubFolder1 as well as the virtual machine is created in the folder root of the location of the model.  For example, if the model is in "DC = > Folder1 = > Subfolder1 = > Subfolder2 ' the virtual machine will be created in the folder Folder1

    Any suggestions on how to ensure that the virtual machine is created in the desired folder/location as well as a list of resources?  In my view, there are really smart guys here and I suspect that this issue would not be a problem at all.  Any help would be appreciated.

    See you soon

    It is not a matter of following the right path.

    You can use the location setting to get the exact folder you want. For example

    $dc = get-data center-name DC1

    $folder = get-file-name Folder1-location $dc

    $subfolder = get-file-name Folder2-location $Folder1

    or

    $dc = get-data center-name DC1

    $subfolder = get-file-name Folder2-location $dc

    You will need to find a "place" in the path to your destination folder where it will be unique.

  • create a new virtual machine with the default settings?

    I was wondering if there was a way to create a new virtual machine with the default settings.

    For example, let's say I want all new Lion VM to have 2 CPU cores. Is there a way to set this automatically? There are other parameters I want a new machine to inherit automatically, I was wondering if there is an automatic way to do this, or is it a feature request...

    Thanks in advance

    lerker wrote:

    Just for my clarification, when you say a vm model, basically I would execute a finder copy then drag back to the VM library, right?

    Yes.

    On the orders of spcirpting, it would be unix commands or are there specific vmware controls that make your job easier (in Applications/VMware\ Fusion/content or elsewhere)...

    IIRC, VMware Fusion 3 and later versions has an AppleScript dictionary, but it is not yet officially supported and may not be able to do what you want so, basically, only Unix Shell scripts, that's what I was referring to.  For an example, see my script attached to the following response: Re: vmware - script of the creation of the vm and the operating system installation process

  • Failed to create new virtual machines on ESXi4.1 due to the error of slot

    Hi people,
    I am unable to create new virtual machines more on ESXi4.1 host due to the error of the slot. Its shows error "number of devices virtual exceeeds the maximum controller. In a cluster, we have 3 host ESXi 4.1.
    Each ESXi is IBM 3850 M2 / x 3950 M2, CPU Cores 24 CPUsx2.665 GHz.Processor Intel Xeon x 7460 @ 2 .66GHz CPU Type

    Please find the attached screenshot. Any help will be much appreciated.

    Thank you
    vmguys

    See http://kb.vmware.com/kb/1016221

  • Clone &amp; new Config on the different data store

    Hi all

    I had a problem where the user try to clone or create a new configuration where the original VM model are stored is full.

    When the data store is almost full, I turn off the "VM creation" in the section resources, I would do this or the LM will be able to use the different data store? otherwise how can I config for the user can store data different from Julie then create a new configuration or a clone.

    Thank you

    Error message here: -.

    * "Clone VM" operation cannot be performed because the data store 'VMFS02' is not

    Enabled.* yes I disable 'VM Creation' resources because of this LUN is almost exhausted.

    In this case, you must use SSmove to migrate the entire tree of virtual machines from a store of data with more free space

  • ESXi 4: error in live migration (VMotion) to the different data store (Local SATA to iSCSI SAN)

    Hi all

    I have a problem during VM migration live in the different data store, the specifications of the virtual machine is just Windows 2003 x 64 installed with the latest VMWare tools.

    Here is the error message:

    Move the virtual machine

    Win2003x64_RST01

    A general error occurred: detected Source this destination could not resume.

    The active state of VM migration

    any idea what could cause this please?

    Kind regards

    AWT

    Check that the machine ESX4 has prevention performance virtualization and data, indicators enabled in the BIOS. I could move 32 bit machines vmotion Unflagged VT turned on in the BIOS, but 64-bit machines could not begin until I activated the flag of VT in the BIOS.

    Also try to clear the mask of the source of the VM CPU before migrating, providing the hosts have the same hardware.

  • Impossible to migrate from windows 2008 to the different data store

    Hai

    When I try to migrate the computer to the different data store I get the error

    "[error caused by file hard to]."

    Thank you

    Concerning

    R.Ramji

    Hello

    first move this virtual machine to another host and try to migration of storage. still, the problem you then close restarts the virtual machine host and try storage vmotion.

    It should work. If the problem continues after the error log.

  • If you have two hard drives, can you wipe the second and just use it as a storage device?

    If you have two HARD drives in a PC Windows 7, can you remove everything (including the System 32, Windows users, literally everything) in the second and still use his computer? All my programs on the first HDD would remain on my PC, but all the files of the second being scratched? I'm running out of space on my first HARD drive and need to know if I can keep the second as storage just pure.

    Thank you.

    Hey Elliot,

    Thanks for posting your query in the Microsoft Community Forums.

    According to the description, it seems that you want to delete all the data on the secondary hard drive without affecting the first hard drive operating system files.

    I'll be happy to help you with this.

    If the operating system (Windows 7) is installed on the first hard drive, it has nothing to do with the second hard disk. You can go ahead and delete all data without hesitation.

    Note: Make sure that you remove the data from the hard drive where Windows 7 is installed.

    If you want to reduce the number of unnecessary files on your hard disk to free up disk space and help your computer run faster, use disk cleanup.

    For more information, see the link.

    Delete files using disk cleanup

    If you have any other questions, feel free to let us know. We will be happy to help you.

  • Can I have two HARD drives in my d7-1448 of the Pavilion notebook?

    Can I have two HARD drives in my d7-1448 of the Pavilion notebook?

    How do you know that one to replace or should I replace both?

    Hi, Bill:

    I like this one... (and so do a lot of other people if you read the comments).

    http://www.Newegg.com/product/product.aspx?item=N82E16822136280

    Paul

  • OsCustomizationSpec and OSCustomizationNicMapping they are a good way to set up the new virtual machine for the model

    I build a script to generate auto magicly VM when I have import information from a csv file. I have the latest PowerCli, I am trying to build servers r2 Sever 2012 model.  I tried several OsCustomizationSpec (OCS) of in the hope of getting something to work, but I had no luck so far.  In VCenter, it shows that it applies the OCS, but is not apear to have an impact on the server.  I have disabled UAC since the last time that I tried it so maybe that will make a difference.  I am under ESXi 5.1 update 2, just to try to give all the necessary information.  Ideally, I'd like Sysprep, the value of intellectual property, change the computer name and join the server to the domain.  That's all! lol I have the book "VMware vSphere PowerCLI Reffernece, automating vSphere Administration, I walked through step by step.  The new version of PowerCli seems not have the x 86 limitation as earlier versions of PowerCli.  I tried so many different things, I'm not sure what to put in place as a starting point.

    # Save the object credentials with permission to join the domain.
    $DomainCredentials = get-Credential "domain\testername."
    # Clone our Spec by adding the domain information.
    $Spec = get-OSCustomizationSpec "Windows Server 2012 R2"
    $Spec += get-OSCustomizationNicMapping - Spec $Spec
    #$Spec | Select *.

    # Get our VM
    # Change network settings
    Get - VM BigServername | Get-NetworkAdapter | Together-NetworkAdapter - NetworkName nic - 172.16.25 - VLAN225 - connected: $true '
    -Confirm: $false | out-null
    # Close the comments to make change.
    Stop-VMGuest - VM $VM - confirm: $false | out-null
    # Wait while feedback stops
    While ($vm. ExtensionData.Runtime.PowerState - not "poweredOff")
    {
    Start-Sleep - seconds 1
    $vm. ExtensionData.UpdateViewData ('Runtime.PowerState')
    }
    # Apply Spec customization to apply the new network settings
    Get - VM "BigServername" |
    Set-VM - OSCustomizationSpec "R2 Windows Server 2012" - confirm: $false |
    Start-VM

    I can rebuild the model, or something else, we must do this work.

    OR - is simply not the best way to configure the VM?  If not, what Sysprep?

    Good news, but first, I would really like to know where the log files are on which server to the OsCustomization process.

    I decided to reverse engineer and create a CSOS within vCeneter and once I got to work, I kept creating new CSO via PowerCli until I could get that to work, create a new virtual machine.  Once I got this to work, I have tryied to apply on a cloned vm, with no parameters. I got it works too.  I tried to go back to my original image, but I couldn't get this to work.  Something's wrong with this picture.  He wrath that the problem was related to the permissions on the local client.

    New OSCustomizationSpec - OrgName company OSType - Windows - ChangeSid-Server "vcenter.dom.com" - name PowerCliOnly4 - persistent administrator-Type FullName - AdminPassword! password123 - zone "Eastern (USA and Canada)" AutoLogonCount - 3 - domain dom dadmin - DomainUsername - DomainPassword! password123 NamingScheme - vm-Description "PowerCli Use only" - confirm: $false

    Get-OSCustomizationNicMapping - OSCustomizationSpec PowerCliOnly4 | Game-OSCustomizationNicMapping - Position 1 - IpMode UseStaticIP - IpAddress 10.10.10.98 - 255.255.255.0 - DefaultGateway 10.10.10.1 Dns subnet - mask "10.10.10.10","10.10.10.11" "-confirm: $false

    This seems to be very picky.  Because the area is one of the parameters, you cannot put it in the DomainUsername, no dom\dadmin. The part that I really want to know how to get more, is what happens if your vm has a different local administrator as the administrator account.  It turns out that FullName - is not the account that it to connect locally with tires. When I created the vCenter Medtronic Chondroitin, I put 'me' in the name and information of the Organization and that's what was settled in the FullName property:

    Name: PowerCliOnlyM
    Type: persistent
    ServerId: /VIServer = dom\[email protected]: 443.
    Server: vcenter.dom.com
    LastUpdate: 24/09/2014 13:33:19
    DomainAdminUsername: dadmin NO dom/dadmin here!
    DomainUsername: dadmin
    Description: PowerCli use only, done manually in vCenter.
    AutoLogonCount: 3
    ChangeSid: true
    DeleteAccounts: false
    DnsServer:
    DnsSuffix:
    Domain: vsi
    Full name: me
    GuiRunOnce:
    NamingPrefix:
    NamingScheme: Vm
    OrgName: CompanyTU
    OSType: Windows
    ProductKey:
    Time zone: (USA and Canada)
    Working Group:
    LicenseMode: NotSpecified
    LicenseMaxConnections:
    EncryptionKey: {-126, 3, 48, 108...}
    ExtensionData: VMware.Vim.CustomizationSpecItem
    ID: PowerCliOnlyM
    UID: /VIServer = vsi\[email protected]: 443/OSCustomizationSpec = PowerCliOnlyM /.
    Client: VMware.VimAutomation.ViCore.Impl.V1.VimClient
    AdminPassword: w
    DomainAdminPassword: N
    DomainPassword: N

    DNS: {10.10.10.10, 10.10.10.11}
    Wins                  :
    SpecId: PowerCliOnlyM
    Spec: PowerCliOnlyM
    SpecType: persistent
    NetworkAdapterMac:
    Position: 1
    IPMode: UseStaticIP
    IP address: 10.10.10.98
    Subnet mask: 255.255.255.0
    DefaultGateway: 10.10.10.1
    AlternateGateway:
    VCApplicationArgument:
    ID: /VIServer = dom\[email protected]: 443/OSCustomizationNicMapping = OSCustomizationNicMappingImpl-PowerCliOnlyM-persistent-1.
    UID: /VIServer = dom\[email protected]: 443/OSCustomizationNicMapping = OSCustomizationNicMappingImpl-PowerCliOnlyM-persistent-1.
    ExtensionData: VMware.Vim.CustomizationAdapterMapping
    Client: VMware.VimAutomation.ViCore.Impl.V1.VimClient
    Version: 1

    I think that it is good to know that the virtual machine reboot 4 or 5 times as it goes through this process.  It breaks is you try and do something for the virtual machine that interrupt the process.  I don't know that I'll think more questions in a second.

    In addition, it cost he had some problems with the put between quotation marks, single or double around the password, but I did not check this again, I just know that once I took them, he began to work.  I ran on other issues while testing as I was using a single IP address, so if I do not disable the test VM, the following would not work because of the conflct network, maybe I shouldn't admit that... lol

  • vCO workflow: create a virtual machine from a model and then ask the user about the CPU, memory size...

    Hi guys,.

    I am trying to create a workflow with vCO that can do the job for me:

    -Create a virtual machine (or maybe a several virtual machines) from a model (the model is in vCenter, of course)

    -L' user who is running the workflow has the thr right to say what he wants for the CPU, the memorysize, the disksize

    Any help?

    I found some workflows in the library can seem to do something similar to what I want, but since I'm a beginner I'd rather have your advice

    Hello there and welcome to vCenter Orchestrator

    Take a look at this series of tutorials to get an idea of how start:

    Create a vCO simple self-service VM Provisioning Portal - part 1

    Create a vCO simple self-service VM Provisioning Portal - part 2

    Create a Simple Self Service VM Provisioning Portal vCO - part 3

    The general approach to take would be to determine which of the clone (or clone and customize) workflows adapts to your nearest need (see your customer vCO: workflows\Library\vCenter\Virtual Machine management\Clone\)

    Then, create a NEW WORKFLOW that calls this one... after that your clone operation is complete, keep the computer turned off virtual and add feeds of extra work from the library to your new workflow that do things like change the amount of Ram, adds disks, change CPU, etc...

    Be sure to watch the videos on http://www.vmwarelearning.com/orchestrator to get a basic understanding of the use of vCO.

  • New virtual machine for the model with the specific name

    Hello

    I'm trying to add some model VM to VAPP using recomposeVApp (...). And it works well except that I can not change the name of the virtual machine while recomposing. It takes the name of the model. But how to add VMS to model with the specific name? I use the v1.0 API.

    This is my code:

    ReferenceType vmTemplateRef = new ReferenceType();
    vmTemplateRef.setName ("MyNewVM"); This name is ignored. The name of the model is taken!
    vmTemplateRef.setHref (vmRef.getHref ()); reference to the model

    CompositionItemParamType vmItem = new CompositionItemParamType();
    vmItem.setSource (vmTemplateRef);

    create the type params VAPP recompose.
    RecomposeVAppParamsType recomposeVAppParamsType = new RecomposeVAppParamsType();
    recomposeVAppParamsType.setName (vAppRef.getName ()); The name of vApp. It is ok.

    added the element of the virtual machine.
    The newItems < CompositionItemParamType > recomposeVAppParamsType = list
    . getItem().
    newItems.add (vmItem);

    Task task = vapp.recomposeVapp (recomposeVAppParamsType);

    Thank you

    Hello

    For after this code fragment:

    vmTemplateRef.setName ("MyNewVM"); This name is ignored. The name of the model is taken!

    The model name is ignored because vmTemplateRef is the only reference to the object that will be used for the operation of recomposition. If changing the name it will be always ignored.

    I think that changing the name of the virtual machine template for recompose cannot be done as follows:

    (1) operation recomposeVApp().

    (2) get the recomposed VAPP

    (3) download the children-> VM you want to change.

    (4) change the name of the virtual computer.

    I hope this helps!

  • I can't create a new virtual machine, for the error "invalid state" of vmware

    Hi, I have an esx server with some production virtual machines vmware;

    Yestarday I made a new VM, suse linux, froma cdrom; but the file system broke down, it has been altered, I don't know why,

    and I had to cancel the machine using the "remove disc";

    After that I could read "a system general error occurred" and when I click on create a new virtual machine (ctrl + n), I can't because the answer is "invalid state".

    When I click on each virtual machine in 'events', I do not see the logs, I see this error "system general error occurred.

    can someone help me? , should I restart the service mgmt-vmware?  (init.d) on the host server?

    Thanks in advance, best regards

    Toscano Max

    If you use Virtual Center, rebbot VC server and try again. If this does not work, you may have to restart the ESX host.

Maybe you are looking for

  • Word of 2016 too slow on el capitan

    Word of 2016 too slow on el capitan

  • Unable to connect communities of support

    I get the we will be back view in Safari, but I can't connect using Chrome. Tried to clear the caches etc. So, I'll have to this post using Chrome. Also how do reset you Safari now there no Option in the drop down menu.

  • Satellite L30 PSL33: Link to the display driver does not work

    I'm trying to download displey drivers but the link does not work Satellite L30 PSL33http://ru.computers.Toshiba-Europe.com/cgi-bin/ToshibaCSG/download_drivers_bios.jsp?service=ru I use dial-up/modem

  • Not the most convenient airport

    I tried to change my user and the airport of "works" password. Airport utility shows green Internet but shows no airport. I tried all the fixes and made sure everything was up to date. When I reset and tried to start over, he's not asking for my sett

  • How to disabled automatically push button

    How can I set the button to be disabled automatically after certain condition. I have attached a simple example just to represent this problem