Author Posts

August 17, 2015 at 2:51 pm

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.

August 17, 2015 at 3:30 pm

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.

August 17, 2015 at 3:44 pm

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.

August 17, 2015 at 4:15 pm

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.

August 17, 2015 at 4:19 pm

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?

August 17, 2015 at 6:07 pm

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.

August 18, 2015 at 4:25 am

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

August 20, 2015 at 4:13 pm

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