Automation

 View Only
  • 1.  how can I manage scheduled task / get serviceinstance object

    Posted Apr 18, 2008 12:01 PM

    Hello,

    I want to manage my scheduled task from powershell, the VI toolkit and the "Reflection.Assembly ::LoadWithPartialName("vmware.vim")" feature.

    I've found in the VI SDK the object structure and methods. The root object is a "serviceinstance" object. How can I get access to my serviceinstance object?

    More generally, how do I get access to "managed object" ?

    Thanks for your help,

    S



  • 2.  RE: how can I manage scheduled task / get serviceinstance object
    Best Answer

    Posted Apr 18, 2008 12:58 PM

    Have a look at these recent posts: and .

    The first 9 lines show how to get the ServiceInstance object.



  • 3.  RE: how can I manage scheduled task / get serviceinstance object

    Posted Apr 18, 2008 02:31 PM

    Thanks Luc,

    I need more help. I can't get to the scheduledtask.

    In fact, I can't run methods on neither the scheduledtaskmanager object, neither on the Moref ... Am I missing something?

    $svcRef = new-object VMware.Vim.ManagedObjectReference

    $svcRef.Type = "ServiceInstance"

    $svcRef.Value = "ServiceInstance"

    $serviceInstance = get-view $svcRef

    $schMgr_ref = $serviceInstance.Content.scheduledTaskManager

    $schMgr_obj=get-view $schMgr

    #ok so far..... but folowing doesn't work

    $foo=$schMgr_ref.RetrieveEntityScheduledTask()

    $foo=$schMgr_obj.RetrieveEntityScheduledTask()



  • 4.  RE: how can I manage scheduled task / get serviceinstance object

    Posted Apr 18, 2008 05:51 PM
      |   view attached

    The $schMgr_obj object was not correct and the method has to be called on the object.

    I hope the following clarifies it a bit more.

    Get-VIServer -Server <VC-server-name>
    
    # Force load (otherwise VMware.Vim objects are not known)
    [http://Reflection.Assembly|http://Reflection.Assembly]::LoadWithPartialName("vmware.vim")
    
    $svcRef = new-object VMware.Vim.ManagedObjectReference
    $svcRef.Type = "ServiceInstance"
    $svcRef.Value = "ServiceInstance"
    $serviceInstance = get-view $svcRef
    
    # This returns a MoRef to the scheduled task manager
    $schMgr_ref = $serviceInstance.Content.scheduledTaskManager
    
    # This return the actual scheduled task manager object
    $schMgr_obj=get-view $schMgr_ref
    
    # The method needs to be called on the object
    # The method requires 1 argument. 
    # As the API Ref states when the parameter is Null the method will return
    # all schduled tasks
    
    $foo=$schMgr_obj.RetrieveEntityScheduledTask($null)
    
    # The method returns an array of ScheduledTask objects
    
    foreach ($task in $foo){
      (Get-View $task).info
    }
    

    Attachment(s)

    ps1
    scheduledtask.ps1   890 B 1 version


  • 5.  RE: how can I manage scheduled task / get serviceinstance object

    Posted Apr 21, 2008 09:19 AM

    thanks Luc for your help.

    I did try this one (i think I've tried all option), but I get an error "the session is not authenticated" from the call retreiveentityscheduledtask ...

    I am logged on the virtual center with an administrator privilege. I am able to crate VM...

    Any idea?



  • 6.  RE: how can I manage scheduled task / get serviceinstance object

    Posted Apr 21, 2008 09:36 AM

    Are you sure you have "administrator" rights all the way up in the VI structure.

    It could be that you only have "administrator" rights on a specific folder and that would allow you create VMs in that specific folder.



  • 7.  RE: how can I manage scheduled task / get serviceinstance object

    Posted Apr 21, 2008 10:32 AM

    well, I use a windows domain account that is local administrator of the Virtual center server.

    I've tried with local administrator account... I setup administrator permission for my specific account... No luck

    By the way, my account can manage scheduled task on the VC with the VI client...

    Local administrators are granted VC adminstrator permission on the "host & cluster" folder... Any other place where to setup right?



  • 8.  RE: how can I manage scheduled task / get serviceinstance object

    Posted Apr 21, 2008 11:31 AM

    Are you by any chance using the debugger in PowerShell Plus ?

    I just had the same message you had.

    Going out of PowerShell Plus and running the script again gave me again a correct list of the scheduled events.



  • 9.  RE: how can I manage scheduled task / get serviceinstance object

    Posted Apr 21, 2008 12:20 PM

    ahahah!!!!!!!!!!!! Can you imagine the pain trying to figure out what's going on?

    Well you were right.

    By the way, I have the same error on a "classic powershell window", that lunching the PS console and loading the PSSNapin.

    If I use the shortcut created by the Toolkit installer, it works!!

    Thanks for your help Luc.



  • 10.  RE: how can I manage scheduled task / get serviceinstance object

    Posted Apr 18, 2008 01:02 PM

    Ok I've found intersting document:

    http://communities.vmware.com/message/878892

    there is an example how to connect to the serviceinstance:

    $svcRef = new-object VMware.Vim.ManagedObjectReference

    $svcRef.Type = "ServiceInstance"

    $svcRef.Value = "ServiceInstance"

    $serviceInstance = get-view $svcRef