Announcement

Collapse
No announcement yet.

Create linked clones in vSphere ?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Create linked clones in vSphere ?

    Hello to all, and let's hope that I posted in the right forum

    I am very new to powershell and powercli, and I found a script on a blog that creates linked clone in vSphere witch it's actually working nice.



    #Requires -version 2

    # TITLE: New-LinkedClone.ps1
    # AUTHOR: Hal Rottenberg
    # Adapted from a technique published originally by Keshav Attrey http://www.vmdev.info/?p=40
    # Also see William Lam's Perl script: http://engineering.ucsb.edu/~duonglt...nkedClone.html
    # And Leo's manual version for ESX 3.5: http://blog.core-it.com.au/?p=333

    param (
    # [parameter(Mandatory=$true)][string]$SourceName,
    [parameter(Mandatory=$true)][string]$CloneName
    )

    # This was edited by me <----------------------------------
    $SourceName = Get-VM Windows.7.ent.x86
    $CloneName = Station01
    # ----------------------------------------------------------------
    $vm = Get-VM $SourceName

    # Create new snapshot for clone
    #$cloneSnap = $vm | New-Snapshot -Name "Clone Snapshot"

    # Get managed object view
    $vmView = $vm | Get-View

    # Get folder managed object reference
    $cloneFolder = $vmView.parent

    # Build clone specification
    $cloneSpec = new-object Vmware.Vim.VirtualMachineCloneSpec
    $cloneSpec.Snapshot = $vmView.Snapshot.CurrentSnapshot

    # Make linked disk specification
    $cloneSpec.Location = new-object Vmware.Vim.VirtualMachineRelocateSpec
    $cloneSpec.Location.DiskMoveType = [Vmware.Vim.VirtualMachineRelocateDiskMoveOptions]::createNewChildDiskBacking

    # Create clone
    $vmView.CloneVM( $cloneFolder, $cloneName, $cloneSpec )

    # Write newly created VM to stdout as confirmation
    Get-VM $cloneName


    I modified some lines in the script but it's not 100% what I want; What I want to is, run the script and create 200 linked clones and increment the virtual machines names by 1 (station01, station02....) and after 200 clones, stop.

    Can somewone has anny ideea ?

    Thanks in advance

  • #2
    Re: Create linked clones in vSphere ?

    Hi ,

    Create a csv file with two colums name them CloneName, SourceName,
    You can then put names using serialize option upto 200 and the custom sourceName or just drag and fill the column with same name

    SourceName CloneName
    win 7 Station001
    win 7 Station002
    win 7 Station003

    Now try this with only 3 machines first (test machines)

    import-csv x:\fileName.csv | foreach{

    $SourceName = $_.SourceName
    $CloneName = $_.CloneName

    Rest of the code
    }
    Thanks & Regards
    v-2nas

    MCTS 2008, MCTIP, MCSE 2003, MCSA+Messaging E2K3, MCP, E2K7
    Sr. Wintel Eng. (Investment Bank)
    Independent IT Consultant and Architect
    Blog: http://www.exchadtech.blogspot.com

    Show your appreciation for my help by giving reputation points

    Comment


    • #3
      Re: Create linked clones in vSphere ?

      If this is for virtual desktops, I would suggest to look into VMware View 4.5
      Marcel
      Technical Consultant
      Netherlands
      http://www.phetios.com
      http://blog.nessus.nl

      MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
      "No matter how secure, there is always the human factor."

      "Enjoy life today, tomorrow may never come."
      "If you're going through hell, keep going. ~Winston Churchill"

      Comment


      • #4
        Re: Create linked clones in vSphere ?

        Thanks for the response 'v-2nas'; I will try the script and come back with a response;

        And no 'Dumber' this are not virtual desktops, is a software company, and I need to install fresh servers for testing only, and I though linked clones are better for my storage space, and time to clone fresh new machines

        Comment


        • #5
          Re: Create linked clones in vSphere ?

          Then VMware Lab Manager might be the product you look for.
          Marcel
          Technical Consultant
          Netherlands
          http://www.phetios.com
          http://blog.nessus.nl

          MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
          "No matter how secure, there is always the human factor."

          "Enjoy life today, tomorrow may never come."
          "If you're going through hell, keep going. ~Winston Churchill"

          Comment


          • #6
            Re: Create linked clones in vSphere ?

            I edited the script and it's working fine even if I have a couple of errors, and I don't know what those are;
            I've attached the script and the errors if someone has the time to fix the errors;

            And thank's verry much for your help
            Attached Files

            Comment


            • #7
              Re: Create linked clones in vSphere ?

              Hi,

              comment out this and then try

              #$SourceName = Get-VM Windows.XP
              Thanks & Regards
              v-2nas

              MCTS 2008, MCTIP, MCSE 2003, MCSA+Messaging E2K3, MCP, E2K7
              Sr. Wintel Eng. (Investment Bank)
              Independent IT Consultant and Architect
              Blog: http://www.exchadtech.blogspot.com

              Show your appreciation for my help by giving reputation points

              Comment


              • #8
                Re: Create linked clones in vSphere ?

                I managed to get it work; all I had to do was delete the space between SourceName, CloneName in the .cvs file;

                Thanks allot for your help

                Comment

                Working...
                X