Skip to main content

jeunium jeunium's Library tagged vmware   View Popular

VMware: VIX API Blog: Call VIX more easily from .NET (plus PowerShell goodness)

"# Before using this sample, download the Daniel Doubrovkine's VIX

# interoperability library from

# http://www.codeproject.com/KB/library/VMWareTasks.aspx

# and change the variable below to point to it.

$vestrisDir = "C:\Vestris.VMWareTasks"



# Run a script inside a VM using VIX. This should work against ESX 3.5

# U2 or higher, as well as VMware Server and Workstation. See below

# for an example.

function Invoke-Script {

param ($hostCred, $guestCred, $vm, $command, $args)



$vmo = get-vm $vm

$vmView = $vmo | get-view

$vmx = $vmView.config.files.vmpathname



$hostNet = $hostCred.GetNetworkCredential()

$guestNet = $guestCred.GetNetworkCredential()



add-type -path "$vestrisDir\1.0\Bin\Vestris.VMWareLib.dll"

add-type -path "$vestrisDir\1.0\Bin\Interop.VixCOM.dll"

$myHost = new-object vestris.vmwarelib.vmwarevirtualhost

$myHost.ConnectToVMWareVIServer("https://" +

$defaultVIServer.Name + "/sdk", 0, $hostNet.UserName,

$hostNet.Password)

$vm = $myHost.Open($vmx)

$vm.Login($guestNet.UserName, $guestNet.Password)

$vm.Execute($command, $args)

}



# Login stuff.

$ip = read-host "Enter the IP of your VC / ESX server"

write-host "Enter login and password to VC / ESX"

$hostCred = get-credential

write-host "Enter login and password to your VM"

$guestCred = get-credential



# Connect to ESX/VC

connect-viserver $ip -credential $hostCred



# This sample restarts the print spooler.

$command = "c:\windows\system32\net.exe"

$args = "restart spooler"

Invoke-Script -hostCred $hostCred -guestCred $guestCred `

-vm "Windows2k3SP2" -command $command -args $args"

blogs.vmware.com/...-plus-powershell-goodness.html - Preview

vmware vixapi

1 - 20 of 47 Next › Last »
Showing 20 items per page

Highlighter, Sticky notes, Tagging, Groups and Network: integrated suite dramatically boosting research productivity. Learn more »

Join Diigo