6.2

Table Of Contents
if (!(Test-Path $csvFile))
{
write-host -ForeGroundColor Red "CSV File not found"
exit
}
"-----------------------------------------------------"
#------------------------- Functions -------------------------
function GetSourceInstallerMD5()
{
$agentInstallerPath = Convert-Path $agentInstaller;
$md5 = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider;
$md5HashWithFormat =
[System.BitConverter]::ToString($md5.ComputeHash([System.IO.File]::ReadAllBytes($agentInstallerPa
th)));
$md5Hash = ($md5HashWithFormat.replace("-","")).ToLower();
return $md5Hash;
}
#------------------------- Main -------------------------
#Get installer MD5Sum
$installerMD5Hash = GetSourceInstallerMD5;
#Connect to vCenter
Disconnect-VIServer $vcAddress -Confirm:$false
Connect-VIServer $vcAddress -user $vcAdmin -password $vcPassword
#Read input CSV file
$csvData = Import-CSV $csvFile
$destFolder = "/home/$guestUser/"
#Handle VMs one by one
foreach ($line in $csvData)
{
$VMName = $line.VMName
$cmd = "rm -rf VMware-viewagent-linux-*"
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
#Upload installer tar ball to Linux VM
Write-Host "Upload File '$agentInstaller' to '$destFolder' of VM '$VMName' with user
'$guestUser'"
Copy-VMGuestFile -HostUser $hostAdmin -HostPassword $hostPassword -VM $VMName -GuestUser
$guestUser -GuestPassword $guestPassword -Confirm:$false -LocalToGuest -Destination $destFolder -
Source $agentInstaller
#Check the uploaded installer md5sum
$cmd = "md5sum VMware-viewagent-linux-*"
Write-Host "Run cmd '$cmd' in VM '$VMName' with user '$guestUser'"
$output = Invoke-VMScript -HostUser $hostAdmin -HostPassword $hostPassword -VM $VMName -
GuestUser $guestUser -GuestPassword $guestPassword -Confirm:$false -ScriptType Bash -ScriptText
$cmd
if($output.Contains($installerMD5Hash))
Chapter 3 Bulk Deployment of Horizon 6 for Linux Desktops
VMware, Inc. 45