none
Script power shell to export virtual machine RRS feed

  • Question

  • Hello there!

    I'm not a expert in powershell or scripting in general. I would like help to create a script that export few virtual machines per time.

    I know how to export a single Virtual machine or All of them.

    Is there any way to export three or four virtual machine per time?

    I've created a script that export the vm and put in a specific folder, it will create a new sub-folder that will get the date as well.

    $dToday = Get-Date -format "MM-dd-yyyy"
    $dLocalPath = "X:\Exported_VM\VM_EXEMPLE" + "$dtoday0"
    New-Item X:\Exported_VM\VM_EXEMPLE\$dtoday -type directory -Force

    # Exporting some virtual machine
    Export-VM -name VM01 -Path X:\Exported_VM\VM_EXEMPLE + "$dToday"

    $dToday = Get-Date -format "MM-dd-yyyy"
    $dLocalPath = "X:\Exported_VM\VM_EXEMPLE1" + "$dtoday0"
    New-Item X:\Exported_VM\VM_EXEMPLE1\$dtoday -type directory -Force

    Export-VM -name VM1 -Path X:\Exported_VM\VM_EXEMPLE1 + "$dToday"

    In this case i'm exporting two virtual machine but are not at the same time.

    Is there any way to put pipe | or & to export simultaneous?

    Thank you very much 


    Na vida há dois caminhos mais só um que vai na direção certa

    Wednesday, February 1, 2017 10:31 AM

Answers

  • You can use jobs or workspaces to do this although the VM Manager may not allow more than one export to happen at a time.

    $dtoday = [datetime]::Today.ToString('M-dd-yyyy')
    $sb = {
    	Param($vm)
    	$localPath = "X:\Exported_VM\VM_EXEMPLE$dtoday0"
    	New-Item $localPath -type directory -Force
    	Export-VM -name $vm -Path $localPath
    }
    
    $vms = 'VM1','VM2'
    $jobs = foreach($vm in $vms){
    	Start-Job -Name $vm -ScriptBlock $sb -ArgumentList $vm
    }
    $jobs | Wait-Job | Receive-Job -Wait


    \_(ツ)_/

    • Marked as answer by Julio Melo Wednesday, February 1, 2017 12:59 PM
    Wednesday, February 1, 2017 11:01 AM

All replies

  • You can use jobs or workspaces to do this although the VM Manager may not allow more than one export to happen at a time.

    $dtoday = [datetime]::Today.ToString('M-dd-yyyy')
    $sb = {
    	Param($vm)
    	$localPath = "X:\Exported_VM\VM_EXEMPLE$dtoday0"
    	New-Item $localPath -type directory -Force
    	Export-VM -name $vm -Path $localPath
    }
    
    $vms = 'VM1','VM2'
    $jobs = foreach($vm in $vms){
    	Start-Job -Name $vm -ScriptBlock $sb -ArgumentList $vm
    }
    $jobs | Wait-Job | Receive-Job -Wait


    \_(ツ)_/

    • Marked as answer by Julio Melo Wednesday, February 1, 2017 12:59 PM
    Wednesday, February 1, 2017 11:01 AM
  • Thanks a million mate!

    As i wrote up there, i'm learning powershell script.

    Have a nice day!


    Na vida há dois caminhos mais só um que vai na direção certa

    Wednesday, February 1, 2017 12:59 PM