Cloning a VM with powerhshell and then somehow automating the running of sysprep OOBE


  • Ok so here is how I am doing this and why

    I have a template server that is my gold std, that is live and running and it gets MS updates and I do not want to sysprep it as it is my live gold std (server 2008r2) I do not want to make it a template as this will destroy my live server and templates are static not dynamic like a live server is.

    I run my powershell script to clone the server:

    basically it shutsdown the VM and then clones it and and changes the VM settings I need to change 

    It restarts the gold std Vm and the cloned VM

    At this point I manually run sysprep OOBE and proceed to reboot and change the server name\add IP and add to domain.

    Boss does not like the fact that the sysprep is a manual process and wants it automated, kind of like using vmware converter does when you check the generalize tab and choose what you want to do.

    I have found a process that mounts the vhd and inserts the registry entry to run sysprep OOBE but my VHD's are stored on a SAN that the VMM machine is not mapped to so I cannot mount the VHD to do this process. I was wondering if there was a commandlet or parameter that I could use in my powershell script process that does a sysprep?

    Stop-scvirtualmachine -vm "2008 template" 
    $VM = Get-SCVirtualMachine -Name "2008 template" 
    $VMHost = Get-SCVMHost -ComputerName "HyperV21.mydomain.local"
    if($VM.Status -eq "PowerOff"){New-SCVirtualMachine -Name "NEW-Server" -VM $VM -VMHost $VMHost -Path "C:\VHDStorage\Volume2" }
    set-scvirtualmachine -vm NEW-Server -description "Customer name and ID"
    #connect to network and set vlan
    $VM1 = Get-SCVirtualMachine -Name "NEW-Server"
    $Adapter = Get-SCVirtualNetworkAdapter -VM $VM1 
    Set-SCVirtualNetworkAdapter -VirtualNetworkAdapter $Adapter  -VirtualNetwork "NetSwitch" -vlanid 1002 -logicalnetwork "NetSwitch1"
    #Add it to the cloud
    $cloud = Get-SCCloud -Name MY_Cloud
    set-scvirtualmachine -VM NEW-Server -Cloud $cloud
    Start-scvirtualmachine -vm "2008 template"
    Start-scvirtualmachine -vm NEW-Server visit my blog

    Wednesday, October 9, 2013 2:34 PM


All replies