PowerCLI

 View Only
  • 1.  How to create Scheduled Task in VC with PowerShell

    Posted Dec 11, 2008 08:44 AM

    Hi Everybody,

    I'm beginer in scripting in PowerShell. Can you give me an example, how to create a new Scheduled Task in the Virtual Center.

    Thanks,

    GB



  • 2.  RE: How to create Scheduled Task in VC with PowerShell

    Posted Dec 11, 2008 09:46 AM

    The current version of the VITK doesn't contain any cmdlets to manipulate scheduled tasks.

    The scheduled tasks that are available in the VC are currently also rather limited.

    See the VC help file for the possibilities (Viewing and Scheduling a Task : Creating a Scheduled Task).

    Is that what you want to do ?

    If yes, you will have to fall back on the SDK.

    Have a look at



  • 3.  RE: How to create Scheduled Task in VC with PowerShell

    Posted Jan 01, 2013 01:04 AM

    Hi,

    I would like to use PowerCLI to manipulate the scheduled tasks in VC.  Something similar to how VM is handled, e.g. Get-task,

    New-task, Set-task, ...etc.  It has been almost four years now.  Is this limitation still there?  We use VMware vSphere PowerCLI 5.1

    Release 1 build 793510.  It doesn't seem to have this capability.

    Thanks!



  • 4.  RE: How to create Scheduled Task in VC with PowerShell

    Posted Jan 01, 2013 10:19 AM

    You're right, there are currently no PowerCLI cmdlets to create, change or delete vCenter scheduled tasks.

    The current solution is to use the APIs.

    See for example Scheduled Tasks – MethodAction



  • 5.  RE: How to create Scheduled Task in VC with PowerShell

    Posted Jan 03, 2013 12:31 AM

    Many thanks LucD.

    I wonder why VMware doesn't have a set of PowerCLI cmdlets for that while it covers pretty much

    everything else...   It is quite handy if it is available.

    Could you post an API example on how to query a VC scheduled task?  E.g. List all exsiting

    "Power-off" tasks.



  • 6.  RE: How to create Scheduled Task in VC with PowerShell

    Posted Jan 03, 2013 06:13 AM

    I am working on a series of blog posts in which I show PowerShell advanced functions that you can use instead of the missing PowerCLI cmdlets for scheduled tasks. You can expect the Get-VCScheduledTask function appearing on my blog this evening (Central Europen Time).



  • 7.  RE: How to create Scheduled Task in VC with PowerShell

    Posted Jan 03, 2013 09:36 AM

    Sure, try something like this

    $si = get-view ServiceInstance
    $scheduledTaskManager = Get-View $si.Content.ScheduledTaskManager
    Get-View
    $scheduledTaskManager.ScheduledTask |
    where {$_.Info.Action.Name -eq "PowerOffVM_task"} |
    Select
    @{N="Name";E={$_.Info.Name}},
    @
    {N="Description";E={$_.Info.Description}},
    @{N="Enabled";E={$_.Info.Enabled}},
    @
    {N="VM";E={Get-View $_.Info.Entity | Select -ExpandProperty Name}},
    @{N="Notification";E={$_.Info.Notification}},
    @{N="Frequency";E={     switch($_.Info.Scheduler.GetType().Name){       'OnceTaskScheduler' {         "Once"      }       'AfterStartupTaskScheduler'{         "After Startup"      }       'HourlyTaskScheduler' {         "Hourly"      }       'DailyTaskScheduler' {         "Daily"      }       'WeeklyTaskScheduler' {         "Weekly"      }       'MonthlyByDayTaskScheduler' {         "Monthly"      }       'MonthlyByWeekdayTaskScheduler' {         "Monthly"      }     }   }},
    @
    {N="Interval";E={$_.Info.Scheduler.Interval}},
    @
    {N="Start Hour";E={$_.Info.Scheduler.Hour}},
    @{N="Start Minute/Delay";E={$_.Info.Scheduler.Minute}},
    @
    {N="Weekday";E={$_.Info.Scheduler.Weekday}},
    @{N="Offset";E={$_.Info.Scheduler.Offset}},
    @{N="Day of the Month";E={$_.Info.Scheduler.Day}},
    @
    {N="Monday";E={$_.Info.Scheduler.Monday}},
    @{N="Tuesday";E={$_.Info.Scheduler.Tuesday}},
    @
    {N="Wednesday";E={$_.Info.Scheduler.Wednesday}},
    @{N="Thursday";E={$_.Info.Scheduler.Thursday}},
    @{N="Friday";E={$_.Info.Scheduler.Friday}},
    @{N="Saturday";E={$_.Info.Scheduler.Saturday}},
    @{N="Sunday";E={$_.Info.Scheduler.Sunday}},
    @{N="Next Run";E={$_.Info.NextRunTime.ToLocalTime().ToString()}},
    @{N="Active Time";E={$_.Info.Scheduler.ActiveTime.ToLocalTime().ToString()}},
    @
    {N="Run At";E={$_.Info.Scheduler.RunAt.ToLocalTime().ToString()}}

    Note that I converted the dates to local time, if you don't want that remove the ToLocalTime method from the last 3 lines.



  • 8.  RE: How to create Scheduled Task in VC with PowerShell

    Posted Jan 04, 2013 06:43 AM

    Excellent!  It works out perfectly.  I also added some other attributes I am interested in, e.g. LastModifiedTime,  LastModifiedUser, and PrevRunTime.

    Thanks LucD.



  • 9.  RE: How to create Scheduled Task in VC with PowerShell

    Posted Jan 08, 2009 05:00 PM

    You can create a powershell script and run it through the windows scheduler...this is an easy way to get around limitations of the VC scheduler.

    G.Joseph

    Austin, Texas