Skip to content

Instantly share code, notes, and snippets.

@lamw
Created June 29, 2017 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lamw/5aefdfb846075252efce1b54e4a6d0a0 to your computer and use it in GitHub Desktop.
Save lamw/5aefdfb846075252efce1b54e4a6d0a0 to your computer and use it in GitHub Desktop.
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