PoshCode Archive  Artifact Content

Artifact bdda621f0e81fd3883084fb3a72ed331ab08ff74f9f06e61175b778444a7aa02:

  • File Vim25-Crazy-Magic.ps1 — part of check-in [77d3a9493c] at 2018-06-10 12:58:07 on branch trunk — Interface with vimService on ESXi. (user: waldo size: 1666)

# encoding: ascii
# api: powershell
# title: Vim25 Crazy Magic
# description: Interface with vimService on ESXi.
# version: 4.0.0
# author: waldo
# license: CC0
# x-poshcode-id: 1524
# x-archived: 2011-01-10T08:49:27
#
#
cls

[void][Reflection.Assembly]::LoadWithPartialName("VMware.Vim");

# generate the proxy
$ws  =  New-WebServiceProxy -Uri "http://172.16.0.33/sdk/vimService?wsdl" ;
$ws.Url = "http://172.16.0.33/sdk/vimService";
$ws.UserAgent = "VMware VI Client/4.0.0";

# I modded the host to accept HTTP requests (too big of a mess with SSL)
# http://www.vmware.com/support/developer/vc-sdk/visdk400pubs/sdk40setupguide.pdf
$vimClient = New-Object Vmware.Vim.VimClient;
$servicecontent  = $vimClient.Connect("http://172.16.0.33/sdk");
$usersession = $vimClient.Login("root","root");

# the below type will be unique to your host.  for some reason the VimApi_25.ManagedObjectReference did not want to pass to the web service
$myMoRef = new-object Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy172_16_0_33_sdk_vimService_wsdl.ManagedObjectReference;
$myMoRef.type = "HostSystem";
$myMoRef.Value = "ha-host";
# yet to figure out where ha-host comes from... 

# cookie monster your session cookies
$ws.CookieContainer = $vimClient.VimService.CookieContainer;

# call your favorite web service method
$ret = New-Object  Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy172_16_0_33_sdk_vimService_wsdl.ManagedObjectReference;
$ret = $ws.RebootHost_Task($myMoRef,$true);
$ret;
$vimClient.Logout();

exit

# thanks jaykul for your omniscent guidance