Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of using vSphere GuestOps API via PowerCLI
$guestOpsMgr = (Get-View $global:DefaultVIServer.ExtensionData.Content.guestOperationsManager)
$authMgr = (Get-View $guestOpsMgr.AuthManager)
$vm = (Get-VM -Name MacOSX-10.11).ExtensionData.MoRef
$credential = New-Object VMware.Vim.NamePasswordAuthentication
$credential.InteractiveSession = $false
$credential.Username = "lamw"
$credential.Password = "vmware123"
$authMgr.ValidateCredentialsInGuest($vm,$credential)
$processMgr = (Get-View $guestOpsMgr.ProcessManager)
$commandSpec = New-Object VMware.Vim.GuestProgramSpec
$commandSpec.WorkingDirectory = "/Users/lamw"
$commandSpec.ProgramPath = "/usr/sbin/system_profiler"
$commandSpec.Arguments = "SPSoftwareDataType > /tmp/output"
$processMgr.StartProgramInGuest($vm,$credential,$commandSpec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment