Helps to create a scheduled task

Hello everyone, I'm trying to get a script to generate scheduled tasks to help in the migration to a new SAN. The script is based on the script of LucD:

$csvName = "C:\Test.csv".
$tgtDatastore = "Datastore1".
$emailAddr = "[email protected]".
$startTime = [Datetime] "10/21/2009-20:00"
$startInterval = 5

$si = get-view ServiceInstance
$scheduledTaskManager is 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. Timer = 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 = [VMware.Vim.VirtualMachineMovePriority] "defaultPriority"
$spec. Action.Argument += $arg2

$scheduledTaskManager.CreateScheduledTask($vm.) MoRef, $spec)
}

I get this error when you try to run it:

Exception calling "CreateScheduledTask" with "" 2″ or arguments: "."
Error while processing 'type' of the attribute with the value "vm".

When parsing MoRef to type vim ManagedObject. ManagedEntity
on line 1, column 320

during the analysis of the CreateScheduledTask method call information
on line 1, column 218

during the analysis of body SOAP
on line 1, column 207

When parsing of SOAP envelope
on line 1, column 38

When parsing the HTTP request method to create
object of type vim.scheduler.ScheduledTaskManager
on line 1, column "0"
Tank line: 34:42
+ $scheduledTaskManager.CreateScheduledTask < < < < ($vm. Moref, $spec)
+ CategoryInfo: NotSpecified: (:)) [], MethodInvocationException)
+ FullyQualifiedErrorId: DotNetMethodException

Thanks in advance to all those who respond.

The way arguments are passed to the RelocateVM_Task in vSphere have changed.

Try this updated version

$csvName = "C:\Test.csv" $tgtDatastore = "MyDS" $emailAddr = "[email protected]" $startTime = [Datetime]"06/21/2012 20:00"$startInterval = 5
$tgtDS = (Get-Datastore -Name $tgtDatastore).ExtensionData$scheduledTaskManager = Get-View ScheduledTaskManager
$offset = 0Import-Csv $csvName | % {
  $vm = Get-View -ViewType VirtualMachine -Filter @{"Name"=$_.VMname}

  $spec = New-Object VMware.Vim.ScheduledTaskSpec  $spec.Name = "svMotion " + $vm.name  $spec.Description = "Migrate " + $vm.name + " 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  $vm.Config.Hardware.Device | where {$_ -is [Vmware.Vim.VirtualDisk]} | %{
    $vDisk = New-Object VMware.Vim.VirtualMachineRelocateSpecDiskLocator    $vDisk.diskId = $_.Key    $vDisk.datastore = $tgtDS.MoRef    $arg1.Value.Disk += $vDisk  }

  $arg1.Value.pool = $vm.ResourcePool  $arg1.Value.host = $vm.Runtime.Host
  $spec.Action.Argument += $arg1

  $arg2 = New-Object VMware.Vim.MethodActionArgument  $arg2.Value = [VMware.Vim.VirtualMachineMovePriority]"defaultPriority"  $spec.Action.Argument += $arg2

  $scheduledTaskManager.CreateScheduledTask($vm.MoRef, $spec)
}

Tags: VMware

Similar Questions

  • 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.

  • Why Media Center now create two scheduled tasks mcupdate AND mcupdate_scheduled?

    I've noticed since starting up Windows Media Center for the first time in a long time on a clean install of Windows 7, it today creates an additional task in the scheduler called mcupdate AND mcupdate_scheduled.  Mcupdate_scheduled is always set to wake the computer at 03:31 every day.  Now in the past to stop Media Center starting the computer for the night and then leaving him on, I would go into media center automatic update options and turn them off.  These options now is more effect Mcupdate or Mcupdate_scheduled and the only way to prevent the center of marketing media automatically is to disable Mcupdate_scheduled in Task Scheduler.  No idea why this strange configuration is in place?  Why is Media Player so determined his will light up in the night by going to the measure of the creation of additional tasks AND prevent you to extinguish itself in Media Player?  Any ideas on that?

    Hello

    1 when was the last time it was working fine?

    2. you have any application security on the computer?

    3 have you tried to remove the Task Scheduler?

    4 did you a recent software or changes to the material on the computer?

    I suggest you remove the task from the task schedular system and check if it helps.

    Description of the scheduled tasks in Windows Vista

    http://support.Microsoft.com/default.aspx/KB/939039

    The above article is for Windows Vista. It remains valid for Windows 7, too.

    You can delete the task in the list and check.

    You can also go through the steps mentioned in the link and check.

    Troubleshooting Task Scheduler

    http://TechNet.Microsoft.com/en-us/library/cc721846.aspx

    Overview of Task Scheduler

    http://TechNet.Microsoft.com/en-us/library/cc721871.aspx

    I hope this helps.

  • Create a scheduled task

    Hi guys,.
    I followed the steps required to create a task scheduled, but due to some reasons its not appearing is not in the list of tasks of planning after importation by file weblogicimportmetadat.bat...

    Here are the details of the xml file: C:\MyDataSets\Custom\metadata\FFLookupRecon.xml

    <? XML version = "1.0" encoding = "UTF - 8"? >
    < scheduledTasks xmlns = "http://xmlns.oracle.com/oim/scheduler" >
    < task >
    < name > FFLookupRecon < / name >
    oracle.iam.connectors.icfcommon.recon.LookupReconTask < class > < / class >
    < description > gets all the roles, such as specified in the target machine < / description >
    < retry > 0 < / re >
    < Parameters >
    < string-required param = 'true' encrypted = 'false' helpText 'The IT resource name' = > IT Resource Name < / param-string >
    object Type < string-required param = 'true' encrypted = 'false' helpText = "Object Type" > < / param-string >
    < string-required param = 'true' encrypted = 'false' helpText = "Search name" > search name < / param-string >
    < string-required param = 'true' encrypted = 'false' helpText "Key Code attribute" = > attribute Key Code < / param-string >
    < string-required param = 'true' encrypted 'false' helpText = 'Attribute to decode' = > decode attribute < / param-string >
    < string-required param = 'false' encrypted 'false' helpText = 'Filter' = > filter < / param-string >
    < / Parameter >
    < / task >
    < / scheduledTasks >


    Here are the details of the file weblogic.properties:

    # Weblogic Server name on which IOM application runs

    wls_servername = oim_server1

    # If you import or export all out of area event handlers, the value is IOM.
    # For the rest of the release of metadata of the box, the value is OIMMetadata.
    # If you import or export all custom data, always use the name of the application as OIMMetadata.

    application_name = OIMMetadata

    # Location of the directory where XML file to be imported.
    # Lets say I want to import User.xml and it is at location scratc/asmaram/temp/oim/file/User.xml,.
    # I should give the value of the location as/scratc/asmaram/temp/IOM. Make sure that no other files are
    # in this folder or its subfolders. Import utility try to recursively import all of the files in the
    # the location folder. This property is used only by weblogicImportMetadata.sh

    metadata_from_loc = C: / / MyDataSets / / Custom / / metadata

    # Location of the directory to be exported to XML file

    metadata_to_loc=@metadata_to_loc

    # E.g. /file/User.xml to export the definition of the user entity. You can specify multiple xml in the form of comma-separated values files.
    # This property is used only by the weblogicExportMetadata.sh and weblogicDeleteMetadata.sh scripts

    metadata_files=@metadata_files

    Any help would be appreciated

    Thank you and best regards,
    Prasad Shinde

    Make sure that you store xml as below

    IE: =C://MyDataSets//Custom//metadata//*db//scheduledtask.xml* xml location

    metadata_from_loc = C: / / MyDataSets / / Custom / / metadata

    Be sure to only run the Purgecache.sh

    Verify MDS pattern to the title of the table MDS_PATHS.

  • 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.

  • Create a scheduled task to backup the catalog recovery - Oracle 11 g

    I used batch files to automate the backup of the production database to perform the task as shown below

    For example, I created a batch file; who should then use a normal Windows Task Scheduler as illustarted below

    Set ORACLE_SID = orcl

    RMAN target / catalog newspaper rman/manager@catdb script C:\Orionbackup\Level0.log APPEND = LEVEL0_BACKUP

    My backup strategy is only half done, since I still need to make a backup of the Recovery Catalog; but I am unable to find a way to automate it. Since I have to connect to with the NOCATALOG RMAN and use the for metadata backup Controlfile; I obviously can't use an RMAN script is that someone has found a way to automate the backup of recovery catalog?

    You can use the tell RMAN cmdfile argument to read a script from an operating system file.

  • Create a scheduled task and deploy on all computers in the domain

    Hi all

    I have the following requirement:

    I need to automatically run a program of cleaning (Glary utilities) on all computers at a time as 10:30 on all computers in the domain. Also all by running the UAC program block and ask the admin domain password every time. I need only this program to be run as a domain user and run at the precise moment on all computers in the domain at a time. How can I do this? Help, please.

    This issue is beyond the scope of this site (for consumers) and to be sure, you get the best (and fastest) reply, we have to ask either on Technet (for IT Pro) or MSDN (for developers)

    If you give us a link to the new thread we can point to some resources it
  • How to create the scheduled task oracle

    DECLARE
    jobno NUMBER;
    BEGIN
    SYS. DBMS_JOB. Send
    (work = > jobno)
    , this = > 'DEL_HIST_TABLE ';
    , next_date = > to_date (September 4, 2009 18:23 ',' dd/mm/yyyy hh24:mi:ss')
    , interval = > 'null '.
    , no_parse = > TRUE
    );
    SYS. DBMS_OUTPUT. Put_line (' job number is: ' | to_char (jobno));
    END;
    commit;


    I wrote the above work to operate on specific date and time

    but I want to convert the same to run

    everyday @ 01:00 using oracle 10 g

    Published by: [email protected] on May 17, 2009 23:39

    Hello

    You must set the interval then:

    MHO%xe> select trunc(sysdate) + 1/24 + 1 from dual;
    
    TRUNC(SYSDATE)+1/24
    -------------------
    19-05-2009 01:00:00
    
    1 rij is geselecteerd.
    
    MHO%xe> DECLARE
      2  jobno NUMBER;
      3  BEGIN
      4  SYS.DBMS_JOB.SUBMIT
      5  ( job => jobno
      6  ,what => 'begin null; end;'
      7  ,next_date => to_date('09/04/2009 18:23:00','dd/mm/yyyy hh24:mi:ss')
      8  ,interval => 'trunc(sysdate) + 1/24 + 1'
      9  ,no_parse => TRUE
     10  );
     11  SYS.DBMS_OUTPUT.PUT_LINE('Job Number is: ' || to_char(jobno));
     12  END;
     13  /
    Job Number is: 21
    
    PL/SQL-procedure is geslaagd.
    
    Verstreken: 00:00:11.39
    MHO%xe> commit;
    
    Commit is voltooid.
    MHO%xe> select interval from user_jobs where job = 21;
    
    INTERVAL
    ----------------------------------------------------------
    trunc(sysdate) + 1/24 + 1
    
    1 rij is geselecteerd.
    

    Published by: hoek on May 18, 2009 08:49 added to example

  • Flash Player a scheduled task is not created

    If I do a new installation of flash player, the installation is completed without error, but no scheduled task is created.

    If I can change the Flash Player to warn and then again to Adobe Settings Manager allows to install updates (I understand need to re - create the scheduled task) I get the following error in the FlashInstall.log

    = X = M/19.0.0.226-2015-10-20 + 08-21 - 39.304 =.

    2015-10-20 + 8-32 - 11.809 1226 1062 [error]
    2015-10-20 + 8-32 - 22.426 [error] 1292 0
    2015-10-20 + 8-32 - 22.462 1226 1062 [error]
    2015-10-20 + 8-32 - 23.611 [error] 1292 0

    no idea what mean these errors?

    I can manually create a scheduled task, but don't know why Flash Installer is unable to create the task.

    It's on Windows 7 64 bit and have the full privileges on the PC.

    Thank you

    Steve

    After further investigation, it seems the permissions on the files in c:\windows\tasks was wrong, and although I had permissions, for some reason the installer never.  I now resolved this problem by correcting the permissions.

    Thank you

    Steve

  • 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.

  • Photos with scheduled tasks

    Hi all

    I'm trying to find a script that will create a scheduled task to take snapshots of a text file at a specific time. The file of text being the names of the virtual machines.

    Any help will be be created.

    What I meant is that you can use the same concept of scheduled task to launch a script.

    In this script, you can read the file with the names of virtual machine and create a snapshot for each of them.

  • Upgrade VMware Tools in the form of scheduled tasks

    Hi all

    I need to upgrade my VM to the latest version of VMware Tools (9.0.10 since 5.1.0 Update 2).

    As some of the virtual machine are used in a production environment, reset must be done during the night on weekends.

    I wanted to create a scheduled task for the automatic update of the VMware Tools, but unfortunately, this task is not available.

    I wonder if there is a way to create tasks scheduled using the Scheduler of vSphere.

    Thank you very much in advance for your help.

    Best regards, Werner

    Hi Werner,.

    PFB the process to install VMtool without restarting the machines.

    1. click on any virtual machine that needs the tools updated

    2. right click on the vm and hover over the comments and select Install/Upgrade VMware tools

    3. click on automatic tools upgrade and Advanced Options enter the command of follow-up

    "/S /v" /qn REBOOT = R.

    VMware KB: Install VMware Tools in a Windows virtual machine

    BR

    JD

  • Scheduled task hidden

    I created a scheduled task a few weeks back and things were very good.

    Since the implementation of the scheduled task, my guy Server reinstalled CF in order to be able to have mutiple instances. Who installed and was done without any problems. After the proceeding, re - install, there was a problem with the task of schedled, so I removed it. After his withdrawal, the next day I discovered that the scheduled task is always the treatment even though I can find no trace of it is planned more.

    We have since re-installed the bodies again. Did not fix it.

    What can I do to get this schedule completely removed from my server? For now, I just removed all the code of the page as no problem, but this isn't the end solution I'm looking for.

    Thanks for any help.

    You can try to change your file of neo - cron.xml, see link below for more information.  I suspect that this file was not overwritten by your new installation.  Remember to save this file before making changes.

    http://kb2.Adobe.com/CPS/000/94a16ba6.html

  • services that run via scheduled task

    Hi all

    I am creating a task scheduled to start/stop services. the scheduled task must be run under the service account with minimal rights, as rights of the user or the user rights of maximum power.
    I created the scheduled task running under the account of service with power user rights to stop a service, but unfortunately the task was doing what it suppose to do.
    I did some troubleshooting and investigated as shown below:
    1. I used the runas command to run net stop under the service account that runs the scheduled task, the service is stopped, as it is assumed
    2. I connect to the server using the account service and disconnected (the session will be shown in the disk for the service account) and at the same time open a session to the server with a different account performed the scheduled task, the task does what it is supposed to do. (the service is stopped)
    Note: the scheduled task is set to enabled (scheduled task to run at a specified time)
    3 when I changed the rights on behalf of rights of administrator power user rights service and perform scheduled task, the task runs correctly and does what he must do.
    4. the service was set to be managed by the user with power, which means that if a user opens a session on the server and try to start/stop the service, he will be able to action and is successful.
    my questions will be as shown below:
    1. to start/stop the service via a scheduled task, the service account needs a session to be able to perform the task?
    2 must. the service account the highest privileges to perform the task?
    3. is there a way to avoid to run the scheduled task to run with minimum privileges? What kind of things need to be done.
    Thanks in advance for your answer.

    I would look at the link below.  This should answer all these questions.

    http://www.Microsoft.com/resources/documentation/Windows/XP/all/proddocs/en-us/sag_tsconcepts03.mspx?mfr=true

  • How to get a scheduled task to run when disconnected, but do not run hidden

    Under XP, I had an installation where I created a scheduled task to open a playlist of music at 07:00 every day which was basically I woke up.  In the evening, I would put my computer to sleep and in the morning, the scheduled task would automatically wake the computer, log in my user account and open the playlist with my music program.   In Windows 7, it's is not possible because:

    1. If I put the "execute task if the user is connected or not," the music program opened by the task is hidden, and I can't control or turn off the music player, because it is hidden.

    2. If I put the task 'Run only when the user is connected', the music player is is more hidden when it is launched, but it does not work in my situation because my computer is configured to automatically disconnect when it goes into sleep mode, and which is usually the case when I want the scheduled task to run.

    It worked perfectly well under XP but under Windows 7 it is broken, because, for some reason if a scheduled task is set on "Run If the user is logged in or not ', the window opened by the scheduled task is always hidden.  This was not the case in XP.  Why is this the case in Windows 7, and is there a way to make it work like it did in XP?

    It's a real shame, because it worked perfectly under XP without the need of any additional software overhead.

    It is the same for Vista. The cause is SECURITY!

    Learn more about it here:
    http://windowsteamblog.com/Windows/b/developers/archive/2009/10/01/session-0-isolation.aspx

    André

    "A programmer is just a tool that converts the caffeine in code" Deputy CLIP - http://www.winvistaside.de/

Maybe you are looking for