Skip to content
Menu
Jumlins TechBlog
  • Home
  • About
Jumlins TechBlog

Backup VMs in a Hyper-V Cluster (Core-version)

Posted on 2010-04-212012-03-06 by Niklas Jumlin

As far as I know, after some googling I couldn’t find any program that could take backups of Virtual Machines running on Hyper-V Core when the .VHD files were located on a Cluster Shared Storage.

If you read my previous post you can probably understand you aren’t able to install any advanced programs in the Core-version either because many required runtime files and libraries aren’t available.

Therefore I decided to write a PowerShell script that would export the machines to a network storage server.

I currently don’t have the required environment to develop or do any testing for this script. Therefore I cannot give you a customized script for your environment or needs.
Please also understand that this script is offered to you freely without any support. Feel free to make your own custom versions of it, while still mentioning me as author for the original script.

Updated 2010-05-12 14:40 UTC +1 (Various fixes/Added option to exclude some virtual machines)

This script can and should be scheduled on every Hyper-V node in your cluster. It can ofcourse be used for backing up VMs in a non-clustered environment. The syntax to execute the script is as follow:

Powershell “& ‘D:\powershell\CreateVmBackups.ps1′”

##  Copyright 2010 Niklas Jumlin
##  VM Handling code based off Tore Lervik.
##
##	Create a backup of all the vm's
##

##  Name this Hyper-V
$name = hostname

##  Where do we wanna store the backups?
$dest = "\\nas1\Backups\Hyper-V Backup"

##  Specify where to save the log
$log = "$dest\CreateVmBackups-$name.log"

##  Excluded Virtual Machines, comma separated: "MACHINE1","MACHINE2"
$excludevm = "Exchangesrv","Win7Reference","WinXP-Pro"

##  Email settings, seperate each recipient with comma and no spaces
$recipient = "user1@domain.com,user2@domain.com"
$from= "administrator@domain.com"
$server = "172.16.30.7"

##  Dont bother these
$type = "Daily"
$currentday = get-date -uformat "%d"
$currentmonth = get-date -uformat "%m"
$date = get-date -uformat "%Y-%m-%d-%A"
$VM_Service = get-wmiobject -namespace root\virtualization Msvm_VirtualSystemManagementService
$ListofVMs = get-wmiobject -namespace root\virtualization Msvm_ComputerSystem -filter  "ElementName <> Name"   

##  Write start time to logfile
$dttm = get-date -uformat "%Y-%m-%d %H:%M:%S"
Add-Content $log "$dttm :: Backup started"

##  Start loop
foreach ($VM in [array] $ListOfVMs)
{

	$VMReturnState = $VM.EnabledState
	$VMName = $VM.ElementName

  ##  This part will exclude Virtual Machines that are specified within the $excludevm array
  if ($excludevm -contains $VMname)
  {
     echo "$dttm :: Excluding $VMName from Backup"
     Add-Content $log "$dttm :: Excluding $VMName from Backup"
  }
  else
  {
  ##  If the virtual machines isn't specified to be excluded, then continue

	if (($VM.EnabledState -eq 2) -or ($VM.EnabledState -eq 32768) -or ($VM.EnabledState -eq 32770))
	{
		$VM.RequestStateChange(32769)
		echo "Saving the state of $VMName - $date"
		$savestart = get-date -uformat "%Y-%m-%d %H:%M:%S"
		Add-Content $log "$savestart :: $VMName : Saving the state"
	}

	while (!($VM.EnabledState -eq 32769) -and !($VM.EnabledState -eq 3))
	{
		Start-Sleep(1)
        $VM = get-wmiobject -namespace root\virtualization -Query "Select * From Msvm_ComputerSystem Where ElementName='$VMName'"
	} 

	if ([IO.Directory]::Exists("$dest\TmpDir\$VMName"))
	{
		[IO.Directory]::Delete("$dest\TmpDir\$VMName", $True)
	}

    ##  Export to Temp dir

	echo "Exporting the VM: $VMName"
	$exportstart = get-date -uformat "%Y-%m-%d %H:%M:%S"
	Add-Content $log "$exportstart :: $VMName : Exporting started"
	$status = $VM_Service.ExportVirtualSystem($VM.__PATH, $True, "$dest\TmpDir")

	if ($status.ReturnValue -eq 4096)
	{
		$job = [Wmi]$status.Job	

		while (!($job.PercentComplete -eq 100) -and ($job.ErrorCode -eq 0))
		{
			Start-Sleep(5)
			$job = [Wmi]$status.Job
			echo $job.PercentComplete
		}
	}

	##	Store the files on in a temp directory before moving them to their location and then rename folder to date of backup.

    ##  Check to see if directories exists before we move
    ##  and create them if they dont exist

    if (![IO.Directory]::Exists("$dest\$VMName"))
    {
          [IO.Directory]::CreateDirectory("$dest\$VMName")
    }
    if (![IO.Directory]::Exists("$dest\$VMName\$type"))
    {
          [IO.Directory]::CreateDirectory("$dest\$VMName\$type")
    }
    if (![IO.Directory]::Exists("$dest\$VMName\$type\$currentmonth"))
    {
          [IO.Directory]::CreateDirectory("$dest\$VMName\$type\$currentmonth")
    }

    ##  Move from Temp directory to correct directory, and rename to date of backup

    [IO.Directory]::Move("$dest\TmpDir\$VMName", "$dest\$VMName\$type\$currentmonth\$date")
    $exportdone = get-date -uformat "%Y-%m-%d %H:%M:%S"
    Add-Content $log "$exportdone :: $VMName : Exporting completed"

    ##  Bring virtual machine back online

    $VM.RequestStateChange($VMReturnState)

    ##  Compress folder with 7-zip (Normal compression level).
    ##  Make sure to have 7-Zip Command Line Version (7za) in C:\Windows\
    ##  7za version when this script was written: 7-Zip 4.65 2009-02-03
    ##  Copyright (c) 1999-2009 Igor Pavlov

    $startcompress = get-date -uformat "%Y-%m-%d %H:%M:%S"
    Add-Content $log "$startcompress :: $VMName : Compression started"
    & 7za a -mx3 -mmt -tzip $dest\$VMName\$type\$currentmonth\$date.zip $dest\$VMName\$type\$currentmonth\$date

    ##  Check to see if 7za succeeded.
    if ($?)  ## if previous command succeeded
    {
    ##  Delete folder if compression is finnished
    [IO.Directory]::Delete("$dest\$VMName\$type\$currentmonth\$date", $True)
    $allfinnish = get-date -uformat "%Y-%m-%d %H:%M:%S"
    Add-Content $log "$allfinnish :: Done with $VMName"
    Add-Content $log "Backup saved to: $dest\$VMName\$type\$currentmonth\$date.zip"
    }
    else
    {
    $allfinnish = get-date -uformat "%Y-%m-%d %H:%M:%S"
    Add-Content $log "$allfinnish :: $VMName : An error occured during compression!"
    }
  }
  echo "Done with $VMName $date"
}
$allfinnish = get-date -uformat "%Y-%m-%d %H:%M:%S"
Add-Content $log "$allfinnish :: Backup finnished"
Add-Content $log " "	

##  Cleanup previous month backups every 28th of current month

if ($currentmonth -eq 1)
{
    $prevmonth = 12
}
else
{
    $prevmonth = $currentmonth - 1
}

if (($currentday -eq 28) -and [IO.Directory]::Exists("$dest\$VMName\$type\$prevmonth"))
{
    Add-Content $log "$allfinnish :: Deleted old backups ($dest\$VMName\$type\$prevmonth)"
    [IO.Directory]::Delete("$dest\$VMName\$type\$prevmonth", $True)
}

##  Email the logfile
$file = $log

$smtpServer = $server
$msg = new-object Net.Mail.MailMessage
$att = new-object Net.Mail.Attachment($file)
$smtp = new-object Net.Mail.SmtpClient($smtpServer)

$msg.From = $from
$msg.To.Add("$recipient")
$msg.Subject = "$type Backup ($allfinnish)"
$msg.Body = "Attached Logfile: $log"
$msg.Attachments.Add($att)

$smtp.Send($msg)

$att.Dispose()

Share on Facebook

50 thoughts on “Backup VMs in a Hyper-V Cluster (Core-version)”

  1. Matjaz says:
    2010-05-12 at 12:02

    Hi!

    Is this script working with online virtual machine, or they’re in saved status when the process of exporting is active? How big TEMP place do you use for your environment. I’ve for about 10 servers W2k8 R2 in production, so i’m not sure about sizing of destination. For some virtuals i’ve fixed disks, and for some also physical access to disk. Is this script suuporting this scenario also with exclude physical disk??? Can you maybe provide option that i could exclude some virtual server from backup. Thanks in advance.

  2. Niklas says:
    2010-05-12 at 12:19

    1. The script will save the state of online machines for about 5 minutes.
    2. Then it will export them.
    3. Bring them back online.
    4. And in the background it will compress the VHD file using 7-zip.

    This script should work with whatever setup you have for you Hyper-V environment, clustered or none-clustered, fixed or dynamic disks doesn’t matter. It will export them just like they are setup. It will not convert a fixed disk to a dynamic disk or vice-versa.

    My environment uses a quite large NAS, about 6TB of space. But you will not have to worry about the tmp directory too much. It is only being used once per machine, and its being cleared whenever its done exporting one machine. So I would say that the tmp location needs to be as big as your largest VHD file.

    BTW, I have updated the script with some various fixes here and there. Please use the new version above.

  3. Niklas says:
    2010-05-12 at 14:48

    I have added your request to exclude some virtual machines. So the script has been updated once again.

  4. 2life says:
    2010-05-21 at 06:37

    Thanks for the script! This is what I need. But in the code you have two errors. This line 1931 ((“ElementName Name” should be replaced by “ElementName Name”), and 127 (extra character “&” before 7za). And do not come log e-mail.

  5. 2life says:
    2010-05-21 at 06:37

    Sorry, line 31)

  6. Niklas says:
    2010-05-21 at 15:06

    Thank you. Its now corrected.

    (The html editor converted “&” to &amp ; and “<" to &lt ; etc... thats why it wasn't working.) Its now fixed.

  7. 2life says:
    2010-05-24 at 17:06

    E-mail send is ok. Problem with my gateway. Script is very good for everyday backup! I’m using this script for my job.

  8. wannascript says:
    2010-05-25 at 02:30

    Thank you for the great script!! Its almost exactly what I needed.
    I dont know scripting, would it be difficult to change this script to have a backup retetion time instead of deleting everything from the previous month? Maybe set it for a retention of 60 days or 14 days?
    Thank you

  9. jirm says:
    2010-05-30 at 13:53

    Hi Niklas.
    Sorry about my english (im spanish)

    I have read your script approach and seems awesome view of that problem.
    I find (and googgled too) for several hours for one really solution for backupU/restore host based VM in hyper-v server R2 in failover (CSV storage) environments without so much luck.
    I found several powershell scripts but dont have rigth solution for CSV host VM backing up (i think better is use diskshadow.exe) because diskshadow dont do consistent state for VM in CSV environments.
    I found one interesting treath that seems make a solution with using a VB6 tool (see: http://social.technet.microsoft.com/Forums/en/winserverhyperv/thread/6957409b-c348-47a8-8ac7-f3ece3c9fbee).

    I have one problem (one more…) when trying to run this tool in hyper-v server because hyper-v server dont have vb6 runtime installed…

    I think that if we can combinate all together (your script+the vb toool for diskshadow in csv) we can make a generic script for bakup/restore “all” hyper-v envioronments in failover cluster hyper-v (with CSV storage of course).

    Thank you

  10. Niklas says:
    2010-06-02 at 11:35

    wannascript: I’m glad you like it. Your request wouldn’t require much time to add. I can make you a custom script for that. I have your email.

    jirm: I will look into that at some point. I will however not update the script with the VB6 tool, I will probably just write a new one. So make sure you take a look at my blog every now and then..

  11. Arnaud Bigot says:
    2010-06-04 at 14:46

    Hi and THX for this great script !
    is it possible to stop VMs before exporting instead of saving state ?

    regards,

  12. Alireza says:
    2010-07-07 at 12:28

    Thank you for the great script! I’ve tested your script today und every thing seems to be OK. The script created the folders with the name of my VM and subfolders, TMPDir and the log file. But the folder VM-name\daily7\2010-07-07-Wensday.zip is empty:
    >>>>>>>>>>>>>>>>>>>>
    __GENUS : 2
    __CLASS : __PARAMETERS
    __SUPERCLASS :
    __DYNASTY : __PARAMETERS
    __RELPATH :
    __PROPERTY_COUNT : 2
    __DERIVATION : {}
    __SERVER :
    __NAMESPACE :
    __PATH :
    Job : \\Hyper-V-Server\root\virtualization:Msvm_ConcreteJob.InstanceID=”
    D500AA38-538D-4EB6-A11E-52DF794A30BF”
    ReturnValue : 4096
    Saving the state of VM_Gast – 2010-07-07-Mittwoch
    Exporting the VM: VM_Gast
    1
    Name : VM_Gast
    Parent : Hyper_V
    Exists : True
    Root : \\Backup-Server\VHD_Backup$
    FullName : \\Backup-Server\VHD_Backup$\Hyper_V\VM_Gast
    Extension :
    CreationTime : 07.07.2010 11:43:05
    CreationTimeUtc : 07.07.2010 09:43:05
    LastAccessTime : 07.07.2010 11:43:05
    LastAccessTimeUtc : 07.07.2010 09:43:05
    LastWriteTime : 07.07.2010 11:43:05
    LastWriteTimeUtc : 07.07.2010 09:43:05
    Attributes : Directory
    BaseName : VM_Gast
    Mode : d—-
    Name : Daily
    Parent : VM_Gast
    Exists : True
    Root : \\Backup-Server\VHD_Backup$
    FullName : \\Backup-Server\VHD_Backup$\Hyper_V\VM_Gast\Daily
    Extension :
    CreationTime : 07.07.2010 11:43:05
    CreationTimeUtc : 07.07.2010 09:43:05
    LastAccessTime : 07.07.2010 11:43:05
    LastAccessTimeUtc : 07.07.2010 09:43:05
    LastWriteTime : 07.07.2010 11:43:05
    LastWriteTimeUtc : 07.07.2010 09:43:05
    Attributes : Directory
    BaseName : Daily
    Mode : d—-
    Name : 07
    Parent : Daily
    Exists : True
    Root : \\Backup-Server\VHD_Backup$
    FullName : \\Backup-Server\VHD_Backup$\Hyper_V\VM_Gast\Daily7
    Extension :
    CreationTime : 07.07.2010 11:43:05
    CreationTimeUtc : 07.07.2010 09:43:05
    LastAccessTime : 07.07.2010 11:43:05
    LastAccessTimeUtc : 07.07.2010 09:43:05
    LastWriteTime : 07.07.2010 11:43:05
    LastWriteTimeUtc : 07.07.2010 09:43:05
    Attributes : Directory
    BaseName : 07
    Mode : d—-
    __GENUS : 2
    __CLASS : __PARAMETERS
    __SUPERCLASS :
    __DYNASTY : __PARAMETERS
    __RELPATH :
    __PROPERTY_COUNT : 2
    __DERIVATION : {}
    __SERVER :
    __NAMESPACE :
    __PATH :
    Job : \\Hyper-V-Server\root\virtualization:Msvm_ConcreteJob.InstanceID=”
    1C33D9F2-D1BE-4E9E-9A06-E806BF128ACB”
    ReturnValue : 4096

    7-Zip (A) 4.65 Copyright (c) 1999-2009 Igor Pavlov 2009-02-03
    Scanning
    Creating archive \\Backup-Server\VHD_Backup$\Hyper_V\VM_Gast\Daily7\2010-07-07-Mit
    twoch.zip

    Everything is Ok
    Done with VM_Gast 2010-07-07-Mittwoch
    >>>>>>>>>>>>>>>>>>>>>>>>>>

    Do you have any idea?
    Thank you in advance!

  13. nus says:
    2010-08-03 at 19:09

    Thanks a lot for this beautiful script

  14. hal says:
    2010-08-08 at 05:23

    Question: Script seems to run perfectly when run from the command line. However, via scheduler, it seems as though the request to put the VM into the saved state is ignored. The script just sits in the loop until you kill it.
    I have even tried to run the scheduled task as admin with the same result. Thoughts?

  15. Conrad says:
    2010-08-18 at 10:57

    Great Script ! Thx for sharing

  16. Brock says:
    2010-08-25 at 22:09

    Am I correct in that this script essentially automates Saving the state of the VM (which essentially turns it OFF) and Exporting the VM and turning it back on?

    Not exactly the same as backing up CSV with a CSV capable VSS writter.

  17. Buen says:
    2010-09-03 at 11:04

    This script works perfectly, but how do I restore ?
    With the import function of the Hyper-V console.

  18. Niklas says:
    2010-09-16 at 11:11

    Alireza: I’m sorry, but I cannot be of help there. But what happens if you try to manually zip the folder?

    Try running:
    & 7za a -mx3 -mmt -tzip test.zip \\Backup-Server\VHD_Backup$\Hyper_V\VM_Gast\Daily7

    You can even try and run the whole powershell script from your hyper-v, so you’ll be able to see the return status of 7-zip.

    ———————————

    hal: Try to run the powershell script manually, and see what it returns.

    ———————————

    Brock: You are correct with your statement. Its just how hyper-v allows us to get a correct version of the VHD. Hyper-V writes back its changes to the VHD first when the VM has been saved or turned off. And first then will it be possible to get a up-to-date version of the VHD and export it.

    ———————————

    Buen: Thank you. You can restore by importing the machine, or by manually creating a new machine with the VHD used as specified hard drive.

    I’m glad and surprised that so many found use for this script!

  19. udi says:
    2010-09-19 at 10:13

    Niklas,
    didnt use the script yet , i have a question regarding were to run the script, you wrote on all nods cluster, in this case should i run
    the script with the matching vm’s that the node holds and exclude the VM’s
    that run on other nodes ?

  20. Niklas says:
    2010-09-20 at 16:30

    It should run from the Hyper-V host. The server where the Hyper-V server role is installed on.
    If you want to exclude a VM it must be a VM that is running on the Hyper-V server where you are editing the script on.
    This script take no care if you are having a cluster or not.

  21. udi says:
    2010-09-21 at 20:52

    Niklas , i have run the script not on core version but the full version.
    it is running with no errors but the zip file on destination is empty, any idea why ?

    thanks

    udi

  22. Niklas says:
    2010-09-29 at 15:43

    Udi:
    Have you put 7-zip command line within your “Windows” folder? – as stated in the script:
    ## Make sure to have 7-Zip Command Line Version (7za) in C:\Windows\
    ## 7za version when this script was written: 7-Zip 4.65 2009-02-03

    Cheers!

    Locksmith Knoxville TN:
    First time reported. I got no idea why this happens. Perhaps its the theme or a bug in the WordPress Blog code.. Does it happen on other WordPress Blogs?

  23. Steven Lewin says:
    2011-01-14 at 08:21

    I’m running this solution on my Windows 2008 Hyper-V R2 Server. Works great.

    http://www.mcbsys.com/techblog/2009/11/setting-up-windows-server-backup-on-hyper-v-server-2008-r2/

  24. Niklas Jumlin says:
    2011-01-28 at 07:31

    Thats new, this wasn’t out when I wrote the script. Thanks a lot.

  25. Amina says:
    2011-03-11 at 06:07

    Backup vms in a hyper v cluster core version.. Slap-up :)

  26. Laurent says:
    2011-10-21 at 18:50

    Very nice script, really useful !! :)
    Thanks for your work and sharing it. So much complete, easy to understand and edit than the “famous” VmBackup scripts that you can see everywhere on the web.
    Wonderful toy for sysadmins.

  27. Laurent says:
    2011-10-25 at 17:11

    Hi, i just wanted to tell you that i modified your script to check if $dest exists before doing anything (useless) .
    Before the start loop, i’ve put :
    if ([IO.Directory]::Exists(“$dest”))
    {

    and after the end of the loop i’ve put:
    } else {
    $errorstart = get-date -uformat “%Y-%m-%d %H:%M:%S”
    echo “$dest unreachable”
    Add-Content $log “$errorstart :: $dest unreachable”
    }

    Well, i’m upgrading your script with “error” reporting in log and email subject/body .
    I’ll share it if anyone is interested and if the results are interesting ;)

  28. nas review says:
    2011-11-17 at 08:31

    I have been surfing online greater than 3 hours these days, but I never found any fascinating article like yours. It’s beautiful value sufficient for me. In my opinion, if all site owners and bloggers made just right content as you probably did, the net can be much more useful than ever before.

  29. Goedkope Schoenen says:
    2011-12-20 at 09:47

    Does anyone have a powershell script for rebooting a vm, without using the requeststatechange(10), because this is a hard reset which results in an error when starting again.

  30. Niklas Jumlin says:
    2012-01-04 at 09:23

    You can use the parameters of Restart-Computer to run the restart operations as a background job, to specify the authentication levels and alternate credentials, to limit the operations that run concurrently, and to force an immediate restart.

  31. Nico says:
    2012-01-10 at 09:24

    Hi and thanks a lot for this script! It’s working really good and helping me a lot!
    But like Alireza I’ve got the same problem, when I try to make the backup over an UNC path. If I choose a local drive location, I don’t see any problems. But as soon as I ask it to save diectly over network, the ZIP data is empty.
    Does it sound familiar to someone?

    Anyway, great job!

  32. Nico says:
    2012-01-11 at 16:01

    It seems that the state save, Snapshot and Export functions are executed by the Computer Account, which was not allowed to access the NAS share.

    If I may do an improvement at the beginning of your script, instead of giving the Hostname, you could use this to get it directly:
    $ipProp = [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties()
    $name = $ipProp.HostName

  33. Admicom says:
    2012-01-22 at 16:48

    Hi guys,

    This script works on my hv1 with several vm but for some vm, the zips are empty. If i deactivate the 7zip in the script, same issue : the folder is empty too…

    Any idea ?

    Nicolas

  34. Donato says:
    2012-01-26 at 10:55

    Hi!
    Great script!
    had the same problem of Alireza and Admicom, found a problem in the export:
    Nico was right: is an access problem to shared folder, solved it works!

  35. Donato says:
    2012-01-26 at 11:13

    Hi Niklas i’m also interestead to to have a backup retetion time of 14 days like wannascript said.
    Can yu post a solution?
    Thank you

  36. Donato says:
    2012-01-26 at 11:47

    On a Cluster configuration may be that a node has no VMs running..
    added an escape instead of saving state:

    ## If the virtual machines isn’t specified to be excluded, then continue else exit from scrip execution

    if (($VM.EnabledState -eq 2) -or ($VM.EnabledState -eq 32768) -or ($VM.EnabledState -eq 32770))
    {
    $VM.RequestStateChange(32769)
    echo “Saving the state of $VMName – $date”
    $savestart = get-date -uformat “%Y-%m-%d %H:%M:%S”
    Add-Content $log “$savestart :: $VMName : Saving the state”
    }
    else
    { echo ” No VMs on $name”
    Add-Content $log “$dttm :: No Vms on $name”
    exit
    }

  37. Admicom says:
    2012-01-27 at 01:18

    I precise that all my VMs are running on the same node. This issue is amazing. Don’t understand.

    Nicolas

  38. Admicom says:
    2012-01-28 at 00:32

    Here is what I obtain :

    __GENUS : 2
    __CLASS : __PARAMETERS
    __SUPERCLASS :
    __DYNASTY : __PARAMETERS
    __RELPATH :
    __PROPERTY_COUNT : 2
    __DERIVATION : {}
    __SERVER :
    __NAMESPACE :
    __PATH :
    Job : \\HYPERV1-W2K8\root\virtualization:Msvm_ConcreteJob.Instance
    ID=”CBD12BF1-F1D0-4AF2-AE8D-4FFBA56A9F32″
    ReturnValue : 4096

    Saving the state of 01_DC-MYCOMPANY – 2012-01-28-samedi
    Exporting the VM: 01_DC-MYCOMPANY
    0
    Name : 01_DC-MYCOMPANY
    Parent :
    Exists : True
    Root : F:\
    FullName : F:1_DC-MYCOMPANY
    Extension :
    CreationTime : 28/01/2012 00:28:22
    CreationTimeUtc : 27/01/2012 23:28:22
    LastAccessTime : 28/01/2012 00:28:22
    LastAccessTimeUtc : 27/01/2012 23:28:22
    LastWriteTime : 28/01/2012 00:28:22
    LastWriteTimeUtc : 27/01/2012 23:28:22
    Attributes : Directory
    BaseName : 01_DC-MYCOMPANY
    Mode : d—-

    Name : Daily
    Parent : 01_DC-MYCOMPANY
    Exists : True
    Root : F:\
    FullName : F:1_DC-MYCOMPANY\Daily
    Extension :
    CreationTime : 28/01/2012 00:28:22
    CreationTimeUtc : 27/01/2012 23:28:22
    LastAccessTime : 28/01/2012 00:28:22
    LastAccessTimeUtc : 27/01/2012 23:28:22
    LastWriteTime : 28/01/2012 00:28:22
    LastWriteTimeUtc : 27/01/2012 23:28:22
    Attributes : Directory
    BaseName : Daily
    Mode : d—-

    Name : 01
    Parent : Daily
    Exists : True
    Root : F:\
    FullName : F:1_DC-MYCOMPANY\Daily1
    Extension :
    CreationTime : 28/01/2012 00:28:22
    CreationTimeUtc : 27/01/2012 23:28:22
    LastAccessTime : 28/01/2012 00:28:22
    LastAccessTimeUtc : 27/01/2012 23:28:22
    LastWriteTime : 28/01/2012 00:28:22
    LastWriteTimeUtc : 27/01/2012 23:28:22
    Attributes : Directory
    BaseName : 01
    Mode : d—-

    __GENUS : 2
    __CLASS : __PARAMETERS
    __SUPERCLASS :
    __DYNASTY : __PARAMETERS
    __RELPATH :
    __PROPERTY_COUNT : 2
    __DERIVATION : {}
    __SERVER :
    __NAMESPACE :
    __PATH :
    Job : \\HYPERV1-W2K8\root\virtualization:Msvm_ConcreteJob.Instance
    ID=”AF1BA7B5-5E6E-4153-804E-E9EAB1D1BC45″
    ReturnValue : 4096

    7-Zip (A) 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18
    Scanning

    Creating archive F:1_DC-MYCOMPANY\Daily1\2012-01-28-samedi.zip

    Everything is Ok

  39. Donato says:
    2012-01-30 at 09:36

    to Admicom:
    the export don’y start…
    try to save in a local directory
    ## Export to Temp dir

    echo “Exporting the VM: $VMName”
    $exportstart = get-date -uformat “%Y-%m-%d %H:%M:%S”
    Add-Content $log “$exportstart :: $VMName : Exporting started”
    $status = $VM_Service.ExportVirtualSystem($VM.__PATH, $True, “$name\TmpDir”)
    ||||||
    change the original $dest with $name in this point and check if export work

  40. Donato says:
    2012-01-30 at 11:26

    sorry, i was wrong
    change “$dest\TmpDir” with “c:\TmpDir”

  41. Admicom says:
    2012-01-31 at 10:52

    Thks Donato.

    I have found the problem : it comes from the snapshots. I have manually merged the snapshots, one by one, with the parent one, renaming *.avhd in *.vhd the latest one, and I finally obtain a unique *.vhd.

    So, the export function works now and the script too. Thank u for your help.

    Bye.

    Nicolas (France)

  42. Niklas Jumlin says:
    2012-02-09 at 13:57

    I’m sorry for my late reply. I see that you have been able to resolve your issue. I hope it works fine now.

  43. Admicom says:
    2012-02-28 at 10:20

    Hi Guys,

    I have a client of mine for whom I’d like to adapt this script.

    The problem is that for this client, many vms are P2V machines, and I have problems when I try to snapshot these P2V vms : the whole cluster crashes !

    So, I have clearly identified the problem so I’d like to adapt it to force the shutdown of the VMs before saving them.

    Please could you help me ?

  44. Niklas Jumlin says:
    2012-02-28 at 14:04

    Try change this line:
    $VM.RequestStateChange(32769)
    to:
    $VM.RequestStateChange(3)

    According to the table found here:
    http://msdn.microsoft.com/en-us/library/cc723874(v=vs.85).aspx

  45. Admicom says:
    2012-02-29 at 17:51

    Thanks.

    I suppose that I have to add a line to restart the vm’s.

    Any idea ?

  46. Admicom says:
    2012-03-01 at 00:23

    I add that i’d like to see in the log file the sizes of the backuped files.

  47. Niklas Jumlin says:
    2012-03-06 at 09:01

    I currently don’t have the required environment to develop or do any testing for this script. Therefore I cannot give you a customized script for your environment or needs.
    Please also understand that this script is offered to you freely without any support. Feel free to make your own custom versions of it, while still mentioning me as author for the original script.

  48. I feel says:
    2013-06-03 at 08:16

    I precisely wished to thank you very much once again. I do not know the things that I might have worked on without the ways provided by you regarding such subject. Previously it was an absolute fearsome case in my opinion, nevertheless seeing a new specialised manner you solved that made me to jump over happiness. Extremely grateful for this support as well as believe you know what a powerful job that you are accomplishing instructing many people through your website. Most probably you have never met all of us.

  49. مشاهدة says:
    2017-06-05 at 23:05

    Great post however I was wanting to know if you could write a litte more on this subject?
    I’d be very grateful if you could elaborate a little bit more.
    Cheers!

  50. www.Radicidipuglia.it says:
    2021-10-02 at 16:53

    Data ddi scadenza. Il motivo? Preferite gli oli biologici.

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Office 365 Groups/Teams powershell reporting script 2019-03-25
  • [Powershell Script] Convert ImmutableID 2018-09-12
  • Script to Schedule Mem and or vCPU up/downgrade 2015-05-13
  • Backing up VMs in Hyper-V 2013-01-09
  • Windows Server 2012 as a Workstation 2012-09-13

Archives

Categories

  • Exchange 2003
  • Exchange 2010
  • HTML/CSS
  • Imagick
  • JavaScript
  • Linux
  • Misc
  • Office 365 / Azure
  • PHP
  • PowerCLI
  • PowerShell
  • Projects
  • Scripts
  • Server
  • System Administration
  • VMware
  • Winbatch
  • Windows
  • Windows Server 2012

Recent Posts

  • Office 365 Groups/Teams powershell reporting script 2019-03-25
  • [Powershell Script] Convert ImmutableID 2018-09-12
  • Script to Schedule Mem and or vCPU up/downgrade 2015-05-13
  • Backing up VMs in Hyper-V 2013-01-09
  • Windows Server 2012 as a Workstation 2012-09-13
©2025 Jumlins TechBlog | Powered by WordPress & Superb Themes