Access to the content of the problems and configuring scheduled tasks

Hi all!

I am new to the community. IM an apprentice in the last year. I'm working with vmware esx / vsphere since August 2009.

In December 2009 I started to script powershell and powerCLI.

Maybe someone can help me, I searched for a long time, but I do not know how.

I have a small script that takes you through some menus. There you can select the data center, the template and insert the name of the virtual machine. Data warehouses and the host or a cluster will automatically get to deploy. In the end, the script creates an INI file like this:

vmname = test

Location = VENV40

Model = w2k3eesp2x32_template

Cluster_Host = adcv43e.xxx.yyyy .net

DatastoreSystem = esx40_nfs01_SystemDrives1

DatastoreSwap = esx40_nfs02_SwapDrives1

VCenterVENV = xx.yy.xx.yyy

Now to my problem. The second script should be an infinite loop, looking if there are a few new INI files.

Due to our policies, we can only deploy during the night (storage overhead). We have 3 "slots".  to 01:00 to 03:00 and 05:00, where we can deploy a virtual machine.

The second script should get the regular deployment of the Vcenter task and check if there is a "slot" to deploy, if not, check the next night and so on.

My problems are:

I can not only the deployment task

The departure time you have a time difference in the vcenter? (eastern daylight time?)

When I got the available task, how to create a new one with the Ini file information?

Someone at - it an idea?

That's what I have so far. It was just to try if I can get the scheduled task

  1. --------------------------------------------------------------------------------------------

  2. Force load (otherwise VMware.Vim items are not known)

http://Reflection.Assembly: LoadWithPartialName ("vmware.vim")

CLS #clearscreen

$svcRef = new-object VMware.Vim.ManagedObjectReference

$svcRef.Type = 'ServiceInstance.

$svcRef.Value = 'ServiceInstance.

$serviceInstance = get-views $svcRef

  1. This returns a MoRef scheduled task manager

$schMgr_ref = $serviceInstance.Content.scheduledTaskManager

  1. This returns the actual scheduled task manager object

$schMgr_obj = get-views $schMgr_ref

  1. The method must be called on the object

  2. The method requires 1 argument.

  3. As the API Ref stipulates that when the parameter is Null, the method will return

  4. all scheduled tasks

$foo = $schMgr_obj. RetrieveEntityScheduledTask ($null)

  1. The method returns an array of task object references

{foreach ($task in $foo)

$infos = (get-view $task) .info

$taskname = $infos. Name

$taskdate =($infos.) Scheduler). RunAt

$task = "$taskname", "$taskdate".

}

#----


Thanking you in anticipation.

I am looking before I heard you and sorry for my bad English

Greetings PowaCLI

There are two problems.

(1) the property $cloneSpec.Location.Pool must a resourcepool pint. In the script below I took the default value (and hidden) resourcepool called Resources.

(2) the $spec. Scheduler property must be one of AfterStartupTaskScheduler, OnceTaskScheduler, RecurrentTaskScheduler.

You will probably need to put the $spec. Scheduler.runAt to the property a value if you want to avoid the task starts immediately.

$taskName = "Create new VM"
$taskHours = 1,3,5
$iniPath = "D:\__IPA_PowerCLI_VM\INI\"

Connect-VIServer 10.11.4.209

$si = Get-View ServiceInstance
$schedMgr = Get-View $si.Content.scheduledTaskManager

$scheduled = @()
$schedMgr.ScheduledTask | %{Get-View -Id $_} | %{
     if($_.Info.Name -like ($taskName + "*")){
          $scheduled += $_.Info.NextRunTime.ToLocalTime()
     }
}

$now = Get-Date -Minute 0 -Second 0
if($now.Hour -gt $taskHours[-1]){
     $now = $now.AddDays(1)
}

$iniFiles = Get-Item ($iniPath + "*") -Include "*.csv"
foreach($iniFile in $iniFiles){
     $params = Import-Csv $iniFile  # -UseCulture
     $notScheduled = $true
     while($notScheduled){
          $taskHours | %{
               $schedTime = $now.Date.AddHours($_)
               if(!($scheduled -contains $schedTime)){
                    $spec = New-Object VMware.Vim.ScheduledTaskSpec

                    $spec.Action = New-Object VMware.Vim.MethodAction

                    $arg1 = New-Object VMware.Vim.MethodActionArgument
                    $arg1.Value = New-Object VMware.Vim.VirtualMachineRelocateSpec
                    $arg1.value = (Get-Folder vm| Get-View).MoRef  # (Get-Folder $params.Location| Get-View).MoRef
                    $spec.Action.argument += $arg1

                    $arg2 = New-Object VMware.Vim.MethodActionArgument
                    $arg2.value = "TESTVM"
                    $spec.Action.argument += $arg2

                    $cloneSpec = New-Object VMware.Vim.VirtualMachineCloneSpec
                    $cloneSpec.Location = New-Object VMware.Vim.VirtualMachineRelocateSpec
                    $cloneSpec.Location.Datastore = (Get-Datastore qesx00_nfs01_SystemDrives1| Get-View).MoRef
                    $cloneSpec.Location.Pool = (Get-cluster QVENV00_Cluster00 | Get-ResourcePool Resources  | Get-View).MoRef

                    $arg3 = New-Object VMware.Vim.MethodActionArgument
                    $arg3.value = $clonespec
                    $spec.Action.argument += $arg3
                    $spec.Action.Name = "CloneVM_Task"
                    $spec.Description = "Test"
                    $spec.Scheduler = New-Object VMware.Vim.OnceTaskScheduler

                    $spec.Enabled = $true
                    $spec.Name = $taskName + " " + $now

                    $entity = Get-Template IPAtestmaschine_Luca | Get-View

                    $schedMgr.CreateScheduledTask($entity.MoRef,$spec)

                    $notScheduled = $false
               }
          }
          $now = $now.AddDays(1)
     }
}

____________

Blog: LucD notes

Twitter: lucd22

Tags: VMware

Similar Questions

Maybe you are looking for

  • How can I prevent popups symbol when I type "ss" or "ll" in a Word?

    How can I prevent OS X 10.11.6 popping symbols when I type "ss" or "ll" in a Word?    In some contexts, typing the second 's' or 'l' is effectively blocked until I have press a different key.

  • How to import a video of pictures of imovie?

    Before I upgraded to OS X El Capitan version 10.11.2, my videos automatically appeared in imovie after a simple command prompt.  The only way that I can download now share them to my desktop and then import into imovie. I would not however hate this

  • Last update of Firmware: Droid RAZR MAXX HD

    Hey guys,. I was wondering what are the latest updates of firmware for Droid RAZR MAXX HD? My backup phone that was running the software 9.20, grabbed the update at 9:30 beginning of last week, but do not seem to phones of my parents who ran the 9.18

  • Picture of front of Sub VI update

    My main screen of the user interface has a picture that put up-to-date control as long as the user interacts with it.  For example, when the user clicks on a certain spot on a picture control, the machine that I am control passes to the location that

  • HP2000 -: recovery of personal records

    I did a system restore. I saved personal files to a flash drive. After system recovery, I did a restore of file with the flash player. He installed the files and gave me a shortcut on the desktop, but they may not return from whence they came. How re