VMware Cloud Community
stm_cro
Contributor
Contributor
Jump to solution

how can I manage scheduled task / get serviceinstance object

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

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Have a look at these recent posts: and .

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
9 Replies
LucD
Leadership
Leadership
Jump to solution

Have a look at these recent posts: and .

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
stm_cro
Contributor
Contributor
Jump to solution

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

Reply
0 Kudos
stm_cro
Contributor
Contributor
Jump to solution

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()

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

stm_cro
Contributor
Contributor
Jump to solution

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?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
stm_cro
Contributor
Contributor
Jump to solution

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?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

stm_cro
Contributor
Contributor
Jump to solution

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.

Reply
0 Kudos