<# .SYNOPSIS This script installs VMware Tools and VMware/Omnissa Horizon Agent on a virtual machine. It checks if the machine is a VMware virtual machine, downloads the latest VMware Tools installer, and installs it silently. It also installs the VMware/Omnissa Horizon Agent from a specified path. .DESCRIPTION https://vm.complianceag.osdcloud.ch .NOTES Version: 0.1 Creation Date: 07.05.2025 Author: Akos Bakos Company: SmartCon GmbH Contact: akos.bakos@smartcon.ch Copyright (c) 2025 SmartCon GmbH HISTORY: Date By Comments ---------- --- ---------------------------------------------------------- 07.05.2025 Akos Bakos Script created #> #region Helper Functions function Write-DarkGrayDate { [CmdletBinding()] param ( [Parameter(Position=0)] [System.String] $Message ) if ($Message) { Write-Host -ForegroundColor DarkGray "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) $Message" } else { Write-Host -ForegroundColor DarkGray "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) " -NoNewline } } function Write-DarkGrayHost { [CmdletBinding()] param ( [Parameter(Mandatory=$true, Position=0)] [System.String] $Message ) Write-Host -ForegroundColor DarkGray $Message } function Write-DarkGrayLine { [CmdletBinding()] param () Write-Host -ForegroundColor DarkGray "=========================================================================" } function Write-SectionHeader { [CmdletBinding()] param ( [Parameter(Mandatory=$true, Position=0)] [System.String] $Message ) Write-DarkGrayLine Write-DarkGrayDate Write-Host -ForegroundColor Cyan $Message } function Write-SectionSuccess { [CmdletBinding()] param ( [Parameter(Position=0)] [System.String] $Message = 'Success!' ) Write-DarkGrayDate Write-Host -ForegroundColor Green $Message } #endregion $Title = "VM Tasks" $host.UI.RawUI.WindowTitle = $Title [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 [System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials $env:APPDATA = "C:\Windows\System32\Config\SystemProfile\AppData\Roaming" $env:LOCALAPPDATA = "C:\Windows\System32\Config\SystemProfile\AppData\Local" $Env:PSModulePath = $env:PSModulePath+";C:\Program Files\WindowsPowerShell\Scripts" $env:Path = $env:Path+";C:\Program Files\WindowsPowerShell\Scripts" $Global:Transcript = "$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-VM-Tasks.log" Start-Transcript -Path (Join-Path "$env:ProgramData\Microsoft\IntuneManagementExtension\Logs\OSD\" $Global:Transcript) -ErrorAction Ignore | Out-Null #region VMware Tools installation If ((Get-CimInstance -ClassName Win32_computersystem).model -like "VMware*") { #================================================= Write-SectionHeader "Install VMware Tools" #================================================= $Title = 'Installing VMware Tools' $host.ui.RawUI.WindowTitle = "$Title" $host.UI.RawUI.BufferSize = New-Object System.Management.Automation.Host.size(2000, 2000) $toolsInstallerPath = "C:\OSDCloud\SW\VMware-tools-latest-x64.exe" # Check if the download was successful if (Test-Path $toolsInstallerPath) { Write-DarkGrayHost "Installing VMware Tools from $toolsInstallerPath" try { # Install VMware Tools silently $Process = Start-Process -FilePath $toolsInstallerPath -ArgumentList "/S /v`"/qn REBOOT=ReallySuppress ADDLOCAL=ALL REMOVE=CBHelper,FileIntrospection,NetworkIntrospection,ServiceDiscovery,Hgfs,VSS,BootCamp,SaltMinion /l*v C:\OSDCloud\Logs\VMware_Tools_Install.log`"" -NoNewWindow -Wait -PassThru # Now we can reliably get the exit code $exitCode = $process.ExitCode # Check the exit code switch ($exitCode) { 0 { Write-DarkGrayHost "VMware Tools installation completed successfully with exit code: 0" } 3010 { Write-DarkGrayHost "VMware Tools installation completed successfully with exit code: 3010 (System restart required)" } 1641 { Write-DarkGrayHost "VMware Tools installation initiated a restart with exit code: 1641" } default { Write-Host -ForegroundColor Yellow "VMware Tools installation completed with non-standard exit code: $exitCode. Check logs for details." } } } catch { Write-Host -ForegroundColor Yellow "Error during VMware Tools installation: $($_.Exception.Message)" } Write-DarkGrayHost "Clean up the installer" Remove-Item $toolsInstallerPath -Force } else { Write-DarkGrayHost "No installer file found at $toolsInstallerPath" } } else { Write-DarkGrayHost "Machine is not a virtual machine" -ForegroundColor Yellow } #endregion #region VMware Horizon Agent installation If ((Get-CimInstance -ClassName Win32_computersystem).model -like "VMware*") { #================================================= Write-SectionHeader "Install VMware/Omnissa Horizon Agent" #================================================= $Title = 'Installing VMware/Omnissa Horizon Agent' $host.ui.RawUI.WindowTitle = "$Title" $host.UI.RawUI.BufferSize = New-Object System.Management.Automation.Host.size(2000, 2000) # Find the installer file $installerFile = "C:\OSDCloud\SW\Omnissa-Horizon-Agent-x86_64-2503-8.15.0-14304348675.exe" if ($null -ne $installerFile) { Write-DarkGrayHost "Installing VMware Tools from $installerFile" try { # Install VMware/Omnissa Horizon Agent silently $Process = Start-Process -FilePath $installerFile -ArgumentList '/s /v"/qn ADDLOCAL=BlastUDP,ClientDriveRedirection,Core,HelpDesk,HznVaudio,HznVidd2,RTAV,USB REBOOT=ReallySuppress SUPPRESS_RUNONCE_CHECK=1 VDM_SKIP_WINDOWS_UPDATE_CHECK=1 IGNORE_PENDING_REBOOTS=1 /l*v C:\OSDCloud\Logs\VMwareOmnissa_HorizonAgent_Install.log"' -NoNewWindow -Wait -PassThru # Now we can reliably get the exit code $exitCode = $process.ExitCode # Check the exit code switch ($exitCode) { 0 { Write-DarkGrayHost "VMware Tools installation completed successfully with exit code: 0" } 3010 { Write-DarkGrayHost "VMware Tools installation completed successfully with exit code: 3010 (System restart required)" } 1641 { Write-DarkGrayHost "VMware Tools installation initiated a restart with exit code: 1641" } default { Write-Host -ForegroundColor Yellow "VMware Tools installation completed with non-standard exit code: $exitCode. Check logs for details." } } } catch { Write-Host -ForegroundColor Yellow "Error during VMware Tools installation: $($_.Exception.Message)" } Write-DarkGrayHost "Clean up the installer" Remove-Item $installerFile -Force } else { Write-DarkGrayHost "No installer file found in C:\OSDCloud folder" } } else { Write-DarkGrayHost "Machine is not a virtual machine" -ForegroundColor Yellow } #endregion Stop-Transcript -ErrorAction Ignore | Out-Null