6.1.1

Table Of Contents
Write-Host "Upload File '$localFile' to '$destFolder' of VM '$VMName' with user '$guestUser'"
Copy-VMGuestFile -HostUser $hostAdmin -HostPassword $hostPassword -VM $VMName -GuestUser
$guestUser -GuestPassword $guestpwd -Confirm:$false -LocalToGuest -Destination $destFolder -
Source $localFile
}
#--------------------- Main --------------------------
#Read input CSV file
Disconnect-VIServer $vcAddress -Confirm:$false
#Connect-VIServer $vcAddress -ErrorAction Stop -user $vcAdmin -password $vcPassword
Connect-VIServer $vcAddress -user $vcAdmin -password $vcPassword
$csvData = Import-CSV $csvFile
foreach ($line in $csvData)
{
$VMName = $line.VMName
$cmd = "sudo /usr/lib/vmware/viewagent/bin/uninstall_viewagent.sh"
Write-Host "Run uninstall cmd in VM '$VMName' with user '$guestUser'"
Invoke-VMScript -HostUser $hostAdmin -HostPassword $hostPassword -VM $VMName -GuestUser
$guestUser -GuestPassword $guestPassword -Confirm:$false -ScriptType Bash -ScriptText $cmd
$cmd = "sudo rm -rf /var/log/vmware/*"
Write-Host "Run cmd '$cmd' in VM '$VMName' with user '$guestUser'"
Invoke-VMScript -HostUser $hostAdmin -HostPassword $hostPassword -VM $VMName -GuestUser
$guestUser -GuestPassword $guestPassword -Confirm:$false -ScriptType Bash -ScriptText $cmd
$cmd = "sudo rm -rf /tmp/vmware-root"
Write-Host "Run cmd '$cmd' in VM '$VMName' with user '$guestUser'"
Invoke-VMScript -HostUser $hostAdmin -HostPassword $hostPassword -VM $VMName -GuestUser
$guestUser -GuestPassword $guestPassword -Confirm:$false -ScriptType Bash -ScriptText
$cmd
}
Disconnect-VIServer $vcAddress -Confirm:$false
exit
Script Execution
The following screen messages show a sample execution of the script:
PowerCLI C:\scripts> .\UninstallAgent.ps1
Your vCenter address: 10.117.44.17
Your vCenter admin user name: administrator
Your vCenter admin user password: *******
--------------------------------------------------
Your ESXi host admin user name, such as root: root
Your ESXi host admin user password: *******
--------------------------------------------------
Your VM guest OS user name: ViewUser
Your VM guest OS user password: *******
After the script completes, View Agent no longer runs on the desktop machines, but the machines and the
desktop pool are not removed from View Connection Server. You can run the View Agent installation script
to install a different View Agent build and the same desktop pool and desktop machines will be available.
Setting Up Horizon 6 for Linux Desktops
34 VMware, Inc.