Reconfigure the scheduled task

With the help of a previous script LucD http://www.lucd.info/2009/10/18/scheduled-tasks-methodaction/ I'm able to succeed in creating a task scheduled that powers on a virtual machine. I need to extend this so that if the existing task is already there it will update with the new configuration. I downloaded the SDK and read the docs to try to understand but he always aludes me.

$dtmDate = get-Date
$gmtoffset = 6
$startTime = $dtmDate.AddHours ($gmtoffset)

$emailAddr = "< emailaddr >.
$vm = "< vm >".
$folder = "SchedTask".
$vmview = get-View (Get - VM $vm)
$folderview = get-View (Get-file $folder)

$spec = new-Object VMware.Vim.ScheduledTaskSpec
$spec. Name = 'Turned on' + $vm
$spec. Description = 'Turned on' + $vm
$spec. Enabled = $true
$spec. Notification = $emailAddr
$spec. Timer = New-Object VMware.Vim.OnceTaskScheduler
$spec. Scheduler.runat = $startTime
$spec. Action = New-Object VMware.Vim.MethodAction
$spec. Action.Name = "PowerOnVM_Task."

$svcRef = new-object VMware.Vim.ManagedObjectReference
$svcRef.Type = 'ServiceInstance.
$svcRef.Value = 'ServiceInstance.
$serviceInstance = get-views $svcRef

$stMgr = get-View ($serviceInstance.Content.ScheduledTaskManager)

$stMgr.CreateScheduledTask($vmview.) MoRef, $Spec)

This should do the trick.

$dtmDate = Get-Date $gmtoffset = 6 $startTime = $dtmDate.AddHours($gmtoffset)

$emailAddr = "[email protected]" $vm = "MyVM" $folder = "SchedTask"$vm = Get-VM $vm
$spec = New-Object VMware.Vim.ScheduledTaskSpec$spec.Name = "Power On " + $vm.Name
$spec.Description = "Power On " + $vm.Name
$spec.Enabled = $true$spec.Notification = $emailAddr$spec.Scheduler = New-Object VMware.Vim.OnceTaskScheduler$spec.Scheduler.runat = $startTime$spec.Action = New-Object VMware.Vim.MethodAction$spec.Action.Name = "PowerOnVM_Task"
$stMgr = Get-View ScheduledTaskManager$stMgr.RetrieveEntityScheduledTask($vm.ExtensionData.MoRef) | %{
    $st = Get-View -Id $_ | where {$_.Info.Name -eq $spec.Name}
}

if($st){
    $spec.Name += " Updated"    $st.ReconfigureScheduledTask($spec)
}
else{
    $stMgr.CreateScheduledTask($vm.ExtensionData.MoRef, $Spec)
}

The script sets the $spec object as before. It then checks if a task with this name already exists for the virtual machine.

If so, it calls the ReconfigureScheduledTask method.

Otherwise, it calls the CreateScheduledTask method.

Note that I have adapted the script a bit to use some features present in newer versions of PowerCLI.

As proof that the existing scheduled task is updated, I change the name for the scheduled task.

But you can change any property in the object $spec in the same way

Tags: VMware

Similar Questions

  • Windows XP Pro - failure of the scheduled task?

    Why my regular job failure?

    Is there an example page on things to do and not do?

    I have a backup program will not work correctly.

    TY,

    Bill

    Hi Bill,

    1. what exactly happens when you run the backup program?

    If a scheduled task does not run when you expect it, right-click the task, and then click Properties. On the Task tab, make sure that the enabled check box is selected. On the tab schedule, check that planning is set correctly.

    See scheduled tasks troubleshooting
    See also How do I solve the scheduled tasks in Windows XP

    Visit our Microsoft answers feedback Forum and let us know what you think.

  • The Event Viewer error on startup: "the scheduled task of CARPET met a failure during configuration data collection. HR = 0xC004F00E.

    I use Windows XP with AMD processor clocked at 1.6 Ghz and 2 GB of RAM. This error appears in the event viewer whenever my computer starts. I don't know if it's doing any harm. can someone advise?

    original title: the scheduled task of CARPET met a failure during configuration data collection. HR = 0xC004F00E

    Hello Steven,

    Did you ever receive notifications that a virus or malware has been removed from your system recently?
    My only thought is that it is the remains of an infection on your machine.
    It is most likely harmless, but I don't understand why you'd be concerned.
    Do you have any task scheduled to run at startup using Task Scheduler built into Windows?
    I would check to see if there are tasks to run at startup:
  • Unable to create restore point. Vista64. Could not create the scheduled task for the following reason: cannot create a file when that file already exists

    RAID 5 obtained corrupte had to rebuild after that can't create system restore point. Tried everything sfc, fsutil, Dungeon SystemPropertiesProtection screen displaying this error: "could not create the scheduled task for the following reason: cannot create a file when that file already exists." (0x800700B7)"system of work in all other respects. SFC says it found and fixed errors every time I run it.

    Fix tried Della Li: Please remove the WindowsBackup folder in the HKEY_LOCAL_MACHINE NT\CurrentVersion\Schedule\TaskCache\Tree\Microsoft\Windows.

    Delete the WINDOWS BACKUP folder. Unfortunately this folder does not exist.

    Checked VSS, Taskscheduler and other services are runnig

    Tried to boot from the CD and widowed revover. Says no problems. The error to any manulation of the checkbox in the properties of the system, the system protection screen

    Solved

    It turns out that task scheduler got corrupted it have several tasks Scheduler said were not available, but are still in the working directory. These tasks especially SR from compensation directory solved the problem and I can now create backup points.

  • Computer not stay awake for the scheduled task

    System wakes up to the task at the right time, but falls asleep almost immediately after starting the task.  Power management is set to put the computer to sleep after 20 minutes, but eventlog shows the alarm system at 01:59 for the scheduled task and to sleep at 02:02.

    Am running Vista Home Basic SP2

    Excellent.  I am pleased to learn that the problem is essentially solved with only a little extra configuration of the task remaining.

    I am happy that I was able to help.  It was my pleasure.

    Thanks for the comments, and we do know that it worked.  This can help other people with the same problem.

    Good luck and best wishes!

    Lorien - MCSA/MCSE/network + / has + - if this post solves your problem, please click the 'Mark as answer' or 'Useful' button at the top of this message. Marking a post as answer, or relatively useful, you help others find the answer more quickly.

  • Change the time for the scheduled task, I added

    I created a schedular system file (.vbs) that supports the backup of the database of one of my application. I added this file to the scheduled task. I put the time of execution to 15:00 daily, now I want to update at the time of execution of the task sacheduled. How can I do? I use Windiws 7 Home premium.

    Hi Aurélie Rozier,.

    Click on the Start button and type "Calendar" in the search box. The option tasks planning must appear in the search list. Click (or double-click) on this option to launch scheduled tasks. When the window tasks planned opens leaves the Task Scheduler list fill out and then look to the bottom of this list for planning thye name, that you want to change. When you have found, right-click on it and choose Properties. In the Properties window, click the triggers tab and then click Edit at the bottom of the special editing window. You should be able to change the time from there.

    This forum post is my own opinion and does not necessarily reflect the opinion or the opinion of Microsoft, its employees or other MVPS.

    John Barnett MVP: Windows XP Expert associated with: Windows Desktop Experience: Web:http://www.winuser.co.uk;  Web: http://xphelpandsupport.mvps.org;  Web: http://vistasupport.mvps.org;  Web: http://www.silversurfer-guide.com

  • SQLcl throws the Exception on start and stop operating within the scheduled task

    I'm on Windows Server 2012 R2 runs a script TakeCommand (jpsoft.com) as a task scheduled using SQLcl - 4.2.0.15.177.0246.

    The script is invoked, when the account (with administrative privileges) who runs the scheduled task is not connected to the machine.

    The scenario is as follows:

    • servers both windows ServerA and ServerB (virtual servers)
    • ServerA has a SAN connected directly (as E drive)
    • ServerB remotely accesses drive E on ServerA and maps in drive E (guest ServerB cmd > net use e: \\ServerA\e)
    • the problem occurs on server b.

    Corr 04/09/2015: the SAN is not the cause of the errors/exceptions - it's just that the user who runs the scheduled task is not logged on and therefore has no APPDATA

    When SQLcl is called, the following lines are recorded... (italics: private information, "BOLD": SQLcl output not visible when the user connects while work is carried out at the request)

    03/09/2015 12:16:41.979 to connect to the jdbc URL ... (this output is to the batch calling SQLcl - everything below is SQLcl or SQL script)

    Sep 03, oracle.dbtools.raptor.console.MultiLineHistory load 2015 12:18:05

    SEVERE: HIST-013 APPDATA is null

    Sep 03, oracle.dbtools.raptor.newscriptrunner.commands.net.NetEntries load 2015 12:18:55

    SEVERE: NET-013 APPDATA is null

    Sep 03, 2015 12:18:55 oracle.dbtools.raptor.newscriptrunner.commands.net.NetEntries save

    SEVERE: NET-013 APPDATA is null

    03.09.2015 12:18:56: updated information on what will be done

    0 lines merged.

    0 lines merged.

    03.09.2015 12:19:15: updated information on what will be done

    0 lines merged.

    Exception in thread "cleansing" java.lang.NullPointerException

    in java.io.File. < init > (File.java:277)

    at oracle.dbtools.raptor.newscriptrunner.commands.alias.Aliases.save(Aliases.java:132)

    at oracle.dbtools.raptor.newscriptrunner.commands.alias.Aliases.save(Aliases.java:128)

    to oracle.dbtools.raptor.scriptrunner.cmdline.SqlCli$ 1.run(SqlCli.java:356)

    In addition, that everything works fine... the script is executed as planned, as expected, the queued files are created...

    So what I am doing wrong?

    Best regards, Peter

    Message geändert durch stueckl - information server added

    Message geändert durch stueckl - information server deleted - it's a general problem

    If we were talking about developer SQL itself rather than SQLcl, then the solution is simple... you can always force your user settings to a folder accessible in arbitrary writing using the ide.user.dir environment variable just add something like this line to the file sqldeveloper.conf to your installation:

    AddVMOption - Dide.user.dir =

    SQLcl, however, is hard-coded dependency on APPDATA in Windows (and user.home on Linux).  May not be feasible in your case, but in some cases simple, APPDATA can be overridden in the script that launches the SQLcl and the NetEntries and xml SQL history files are read from / written to this file.

    For example: value APPDATA = C:\Temp

  • Move VM to csv file and create the scheduled task in VC

    What is the problem with the last line ' $scheduledTaskManager.CreateScheduledTask ($vmView.MoRef, $task) "?

    1. The ScheduledTaskManager lies in the Service Instance.

    $si = get-view ServiceInstance

    $scheduledTaskManager is Get-view $si. Content.ScheduledTaskManager

    1. We need to identify the virtual machine and the host where it will be powered on.

    #$vmView = get - VM PowerOnTest | Get-View

    #$esxView = get-VMHost esx35 - 01.vitoolkit.local | Get-View

    foreach ($f in (import-csv '

    'D:\MigrateStorage\amsterdam-core-hp-poweron.csv'))

    {

    $vmView = $f

    *

    echo $vmView

    *

    }

    1. Now we build the task argument.

    $arg = New-Object VMware.Vim.MethodActionArgument

    #$ARG value = $esxview. MoRef

    $action = New-Object VMware.Vim.MethodAction

    $action. Argument = $arg

    $action. Name = "PowerOnVM_Task".

    $scheduler = new-object VMware.Vim.OnceTaskScheduler

    $scheduler.runat = .addminutes (5) (get-date)

    $task = New-Object VMware.Vim.ScheduledTaskSpec

    $task. Action = $action

    $task. Description = 'start a virtual machine with a scheduled task '.

    $task. Enabled = $true

    $task. Name = 'Virtual Machine market '.

    $task. Programmer = $scheduler

    $scheduledTaskManager.CreateScheduledTask ($vmView.MoRef, $task)

    The following script should do the trick.

    $csvName = 
    $tgtDatastore = 
    $emailAddr = 
    $startTime =                   # Ex [Datetime]"10/21/2009 20:00"
    $startInterval = 
    
    $si = get-view ServiceInstance
    $scheduledTaskManager = Get-View $si.Content.ScheduledTaskManager
    
    $offset = 0
    Import-Csv $csvName | % {
         $vm = Get-View -ViewType VirtualMachine -Filter @{"Name"=$_.VMname}
    
         $spec = New-Object VMware.Vim.ScheduledTaskSpec
         $spec.Name = "svMotion " + $_.VMname
         $spec.Description = "Migrate " + $_.VMname + " to " + $tgtDatastore
         $spec.Enabled = $true
         $spec.Notification = $emailAddr
         $spec.Scheduler = New-Object VMware.Vim.OnceTaskScheduler
         $spec.Scheduler.runat = $startTime.AddMinutes($offset)
         $offset += $startInterval
         $spec.Action = New-Object VMware.Vim.MethodAction
         $spec.Action.Name = "RelocateVM_Task"
    
         $arg1 = New-Object VMware.Vim.MethodActionArgument
         $arg1.Value = New-Object VMware.Vim.VirtualMachineRelocateSpec
         $arg1.Value.datastore = (Get-Datastore $tgtDatastore | Get-View).MoRef
          $arg1.Value.pool = $vm.ResourcePool
          $arg1.Value.host = $vm.Runtime.Host
    
         $spec.Action.Argument += $arg1
         $arg2 = New-Object VMware.Vim.MethodActionArgument
         $arg2.Value = [http://VMware.Vim.VirtualMachineMovePriority|http://VMware.Vim.VirtualMachineMovePriority]"defaultPriority"
         $spec.Action.Argument += $arg2
    
         $scheduledTaskManager.CreateScheduledTask($vm.MoRef, $spec)
    }
    

    Although the scheduled task will trigger a svMotion, CreateScheduledTask method seems still need a host and resourepool MoRef in VirtualMachineRelocateSpec argument.

  • Status of the scheduled task

    Hello

    In our current setup, we need trigger report of the editor on the completion of an external task.

    We use the Editor (ScheduleRequest) web services to start the generation of report and then to an FTP server.

    However, we must now trigger another task based on completion of the scheduled task from the Publisher.

    ScheduleRequest returns the job ID.

    1. How will I know the status of the current job and if the task succeeded or failed?

    Thank you
    Sheela

    To get the status use the operation getScheduledReportStatusRequest with parameters
    -scheduledJobID
    -user name
    -password

    He'll be back
    -jobId
    -the State of the job application jobStatus. Possible values are: 'Done', 'Error', 'Running', 'Regular', 'Hanging', 'unknown '.
    -message

  • Trying to enable and disable the scheduled tasks back but becomes "the name of the specified task * does not exist in the system.

    I am trying to create a .bat file that stops a set of scheduled tasks and start another game, but when it works it is said that there is no such thing as the name of the task

    SCHTASKS/Change/disable /TN ImageCopyTest
    ERROR: The name of the specified job 'ImageCopyTest' does not exist in the system.

    Running schtasks/query does not list the tasks that I have implemented in Task Scheduler

    For operational reasons, the tasks are set on "Run If the user is logged in or not ' and I read somewhere that this automatically makes the hidden task

    Can someone shed light on how I can get around what I need this operation for our recovery after disaster

    It's on Windows Server 2008 R2 Enterprise

    Hello

    Apologize for the delay in response. Because the question you posted is related to Windows Server and more complex than that which are usually dealt with here, this issue will be safer in our MSDN forums that cater to the more THIS professional audience.

    Thank you.

  • What is the scheduled task ' in * ' (there are a lot of tasks (At25 - At192))

    I use Ccleaner on my desktop and it showed a lot of tasks scheduled with the name 'At' and a number behind them (25-192). They seem to be run by the same file "WQ3203G0.exe", so I was wondering what all these tasks/is this file?

    There is a certain malware (details of which I can't find in my notes) which creates a lot of scheduled tasks in your system, so it seems that your system is currently or has been infected by malware.

    Tell us about your system and run some known malware scanners on request and you can clean up the mess that might be left behind.

    Since the implementation of the Microsoft Answers forum does not ask for any kind of information system when a new question is asked, we know absolutely nothing about your system.  Not knowing the basic information a problem prolongs the frustration and the agony of these issues.

    Thank you MS Answers, allowing the resolution of simple problems as frustrating and a lot of time as possible.

    Provide information on your system, the better you can:

    What is your system brand and model?

    What is your Version of XP and the Service Pack?

    Describe your current antivirus and software anti malware situation: McAfee, Symantec, Norton, Spybot, AVG, Avira!, MSE, Panda, Trend Micro, CA, Defender, ZoneAlarm, PC Tools, Comodo, etc..

    The afflicted system has a working CD/DVD (internal or external) drive?

    You have a genuine XP installation CD bootable, which is the same Service as your installed Service Pack (this is not the same as any recovery CD provided with your system)?

    No matter what you use for malware protection, follow these steps:

    Download, install, update, and make at least an analysis full (not at the same time) with these free malware detection programs:
    SUPERAntiSpyware: (SAS): http://www.superantispyware.com/

    These comprehensive analyses can take some time, but you really need to run.  SAS will probably be just a bunch of Internet tracking cookies, but you can remove them.  Once you have done at least a full analysis, you can do quick scans in the future to save time and save the analyses complete for when you have more time or are really suspicious of an infection of the system.

    They can be uninstalled later if you wish.

  • Permission to create/run the scheduled task

    Hello

    I'm running Windows 7 Pro RTM and I try to use my normal user account to create and run a new scheduled task, but whenever I try to save the task, I get an error msg saying "Task Scheduler cannot create the task.» Does not know the user account, the password is incorrect or the user account doesn't have permission to create this task".

    I have no problems running tasks under my admin account, but I don't want to use it for everyday purposes. I'm also sure that this error must be because of permissions problems, so can I know what is the privilege that a user must have to create/run one account task?

    Thank you very much

    Hi hifer,.

    Please use the forum for answers,

    If your account is a standard account, you will not have permission to create a task or schedule task.  Your account must be an administrator account to schedule the task for the system or it must be run as an administrator.

    It have additional permissions, you can add standard user profile to allow the profile to create the task.  But this option is not available in all versions of Windows and rather complicated.  You can try to add these groups to your profile using computer management in administrative tools.  User with power and Backup administrator can provide you with the authorization that you need if the groups are available with your version of Windows 7.

    Hope this helps,

    Kevin
    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • cron job Monitor and the status of the scheduled task

    I can't find all the rules for the cron and scheduled task of monitoring, any suggestions?

    Thank you

    Rachel

    Hello

    It will be interesting to see what other solutions the Foglight user community found for this.

    A simple option I can think of is having the task cron/writing to a file log and this logfile with LogFilter monitoring officer

    http://en.community.Dell.com/TechCenter/performance-monitoring/Foglight-administrators/w/Admins-wiki/5646.monitoring-application-availability-using-Foglight-utility-agents

    Golan

  • Why the scheduled task cannot rename?

    In Windows 7, after that I put a scheduled task, the task name cannot be renamed.

    Does anyone know a trick to rename rather than create a new one?

    Thanks in advance for your suggestions

    Yes, it's fast & simple.

    Export the task in any convenient folder.  [Export is on the right side of the window TS]

    It is saved as an xml file.

    Switch to the folder in Windows Explorer and rename the xml file with any name you want to change the task.

    Import the xml file.  [Import is also on the right side of the window TS]

    You will then see a task with any name you call the xml file.

  • How to force the display of user account control to run the scheduled task

    I have User Account Control setting on notify me when a program wants to make changes to my computer (the recommended setting).

    I created a scheduled task: create a restore point, using a software called Quick Restore Maker. User accounts in the program control screen comes up and stays on, ends by closes but ends the program. As I'm not at the computer when running task, I can't cancel the screen. The display ends by disappears, but the program itself does not run.

    So the question is: How can I force screen UAC a program to run without changing the UAC universal computer settings that would allow any program to change my computer without any intervention from me?

    Thanks for your help.

    There is no way around the need for approval of Admin indicated by the parameter of the UAC.

    Reduce the level of UAC would be the only thing you can try, but I understand that this would not be a safe way to proceed for normal operation.

Maybe you are looking for