Link to home
Start Free TrialLog in
Avatar of Matthew Cioffi
Matthew CioffiFlag for United States of America

asked on

Setting up VMWare powercli task in schdeduled tasks

I'm new to the VMWare powercli and I'm having some trouble making sense of the proper method of setting up a task in the scheduler.  

What I need to do is setup a scheduled task that will revert a VM back to a snapshot each sunday.  I'm open to any suggestions on how to proceed.


I was able to make this work properly to revert the VM back to the proper snapshot.  How can I have this kicked off at a specific time and day of the week?

$snapshot = Get-Snapshot -VM vapptest -Name "clisnaptest"
Set-VM -VM vapptest -Snapshot $snapshot

Overall we will be rolling out a process that we will rollback several systems to a baseline GA build every sunday evening.  I want to have this scheduled so it happens automatically.
ASKER CERTIFIED SOLUTION
Avatar of Andrew Hancock (VMware vExpert PRO / EE Fellow/British Beekeeper)
Andrew Hancock (VMware vExpert PRO / EE Fellow/British Beekeeper)
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Matthew Cioffi

ASKER

Thanks, I have seen that walk through but I'm not comfortable with it yet.

I will have another go at it and see how it goes.  We have another project taking up lots of time as well.

I have not used this tool at all, it is new to me.
Ok, getting much closer.
I have a couple of questions about the script itself.  Overall it is a pretty simple task, but I need to be able to respond to the prompts and I would like add the credential file instead of leaving my user name and password exposed in the script.  So I have the following points if you can help me out.

1. Add the credential file into this process
2. Allow execution of the script:
           I know that I can run Set-ExecutionPolicy RemoteSigned or Set-ExecutionPolicy Unrestricted but it prompts me for:
          [Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
3. Same issue with my script below.  It will ask me for Y,A,N,L,S,?

How do I use the default or set the confirm to false?

connect-VIServer -Server VCAVCENTER -User domain\CIOFFI -Password password321
$snapshot = Get-Snapshot –VM vrefservername –Name ”vrefservername_base”
Set-VM –VM vrefservername –Snapshot $snapshot

I'm calling the script from the command line, the calling works fine but the script does not:

C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" "& 'C:\testing\revert_vrefservername_snap_.ps1'"

Thanks.
I think I have the solution.

I will post after a couple of test runs.

Thanks.
I have figured out what i needed.

By using a batch file and the task scheduler I was able to fully build out my solution.