Scheduled VM Export

This topic contains 7 replies, has 2 voices, and was last updated by Profile photo of Robert Gardner Robert Gardner 1 year, 7 months ago.

  • Author
    Posts
  • #28673
    Profile photo of Robert Gardner
    Robert Gardner
    Participant

    I am very new to PowerShell. That being said, I have been trying to wrap my head around the script that Jeff Hicks has to schedule xx VM export on a monthly and weekly basis. My problem is that I need the script to export daily and retain the exports for 7 days. Could someone please help. I would be please to do this offline if it is too much for the forum. Thanks in advance.

  • #28675
    Profile photo of Jeffery Hicks
    Jeffery Hicks
    Participant

    You're going to have to help me out and point me to the original script. That said, if you have that kind of backup requirement, you should look into a commercial product like something from Veeam or Altaro.

  • #28676
    Profile photo of Jeffery Hicks
    Jeffery Hicks
    Participant

    I had to Google myself to find this but I think this is the article and script you are referring to: http://www.infoworld.com/article/2610395/windows-server/two-tricks-to-automate-the-export-of-live-vms-in-windows-server.html

    Of course it would be possible to modify the script to meet your daily requirements. But if you are really new to PowerShell you will find yourself lost and overwhelmed very quickly. You really need to take the time to learn PowerShell from the beginning and not simply jump into writing PowerShell scripts, at least in my opinion.

    All that said, you might be able to simply change the Weekly type to Daily and change the retain variable to 7. Of course you still need to create the corresponding PowerShell scheduled job.

  • #28677
    Profile photo of Robert Gardner
    Robert Gardner
    Participant

    Thanks for the reply Mr. Hicks, or may I call you Jeff?

    Agreed, I am not jumping into writing scripts just yet, but I am diligently trying to solve a problem for a few small clients. I have downloaded and looked at the Veeame and Altaro free products, and neither suite my particular requirement. I can explain but that is another issue.

    You are correct as to the article from Infoworld. That article has caused me to go completely through the Jumpstart videos and begin reading the "Month of Lunches" books. I'm not ready to become a tool builder yet, but pray I will become one in the coming months.

    Now, back to my issue; I have a test server with W12R2 and 3 VMs (2 W12R2 & 1 W7). I actually did change both of the entries you suggested and using your example (and some other things I have learned), the command I pass to the script is:

    PS> Get VM | Where {$_.State -eq 'Running'} | C:\Scripts\VMExport.ps1 -Path E:\Export -weekly

    The result is it still asks for a VM name at positon 0, 1....

    I know I am missing something in the command or in something else that needs to change in the script. Any ideas?

    Add on at 9:04 p.m.
    I removed the -weekly argument and the script ran. WhooHoo!!

    Now I will continue to play with your script and commands to see just what else I can make this do. Thanks.

  • #28678
    Profile photo of Robert Gardner
    Robert Gardner
    Participant

    Under the "Param" section can I change:

    [Parameter(Position=2)]
    [switch]$Monthly,

    to

    [Parameter(Position=2)]
    [switch]$Daily,

    and if so, what else needs to change to facilitate that change?

  • #28684
    Profile photo of Robert Gardner
    Robert Gardner
    Participant

    I removed the -weekly argument and the script ran. WhooHoo!!

    Now I will continue to play with your script and commands to see just what else I can make this do. Thanks.

  • #28698
    Profile photo of Jeffery Hicks
    Jeffery Hicks
    Participant

    As you can tell there is a lot of trial and error especially for someone just starting out. Keep plugging away.

  • #28838
    Profile photo of Robert Gardner
    Robert Gardner
    Participant

    I still have a nagging problem. In the arguments for Register-ScheduledJob, other than a single VM name in quotes or a comma seperated list of VM names each in quotes, Get-VM in any form as either a variable or the command itself will not work. I have tried several with and without brackets () around the entire command such as: Get-VM | Where {$_.State -eq 'Running'}, (Get-VM).Name or just Get-VM. The following is the entry from the event log:

    Error Message = The running command stopped...Stop: A parameter is invalid. Hyper-V was unable to find a virtual machine with name Microsoft.HyperV.PowerShell.VirtualMachine.Fully Qualified Error ID =
    InvalidParameter,Microsoft.HyperV.PowerShell.Commands.ExportVMCommand

You must be logged in to reply to this topic.