<# .SYNOPSIS Move Citrix WEM Cache to D:\WEMCache on VDI with MCS cache disk. .DESCRIPTION Checks if D:\WEMCache exists. If not: - Stops WEM services - Creates folder - Sets registry key - Starts services - Verifies result .NOTES Author: Balint Oberrauch Last Updated: 2025-05-21 #> Begin { $script_path = $MyInvocation.MyCommand.Path $script_dir = Split-Path -Parent $script_path $script_name = [System.IO.Path]::GetFileName($script_path) $WEMHostService = "WemAgentSvc" $WEMLogonService = "WemLogonSvc" $NewCachePath = "D:\WEMCache" $RegPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Norskale\Agent Host" $RegName = "AgentCacheAlternateLocation" } Process { try { Write-BISFLog -Msg "Checking for WEM services..." -ShowConsole -Color Cyan $hostSvc = Get-Service -Name $WEMHostService -ErrorAction SilentlyContinue $logonSvc = Get-Service -Name $WEMLogonService -ErrorAction SilentlyContinue if (!$hostSvc) { Write-BISFLog -Msg "$WEMHostService not found. Exiting." -ShowConsole -Color Red return } if (!(Test-Path $NewCachePath)) { Write-BISFLog -Msg "Cache folder not found at $NewCachePath. Proceeding to reconfigure." -ShowConsole -Color Yellow Write-BISFLog -Msg "Stopping WEM services..." -ShowConsole -Color Cyan if ($logonSvc) { Stop-Service -Name $WEMLogonService -Force -ErrorAction SilentlyContinue } Stop-Service -Name $WEMHostService -Force -ErrorAction SilentlyContinue Write-BISFLog -Msg "Creating cache directory at $NewCachePath..." -ShowConsole -Color Cyan New-Item -Path $NewCachePath -ItemType Directory -Force | Out-Null Write-BISFLog -Msg "Setting registry value for WEM cache path..." -ShowConsole -Color Cyan Set-ItemProperty -Path $RegPath -Name $RegName -Value $NewCachePath $regCheck = (Get-ItemProperty -Path $RegPath -Name $RegName).$RegName if ($regCheck -eq $NewCachePath) { Write-BISFLog -Msg "Registry updated successfully." -ShowConsole -Color Green } else { Write-BISFLog -Msg "Registry update failed. Exiting." -ShowConsole -Color Red return } Write-BISFLog -Msg "Starting WEM services..." -ShowConsole -Color Cyan Start-Service -Name $WEMHostService if ($logonSvc) { Start-Service -Name $WEMLogonService } # Verify services $hostStatus = (Get-Service -Name $WEMHostService).Status $logonStatus = if ($logonSvc) { (Get-Service -Name $WEMLogonService).Status } else { "Not Installed" } Write-BISFLog -Msg "WEM Host Service status: $hostStatus" -ShowConsole -Color Green Write-BISFLog -Msg "WEM Logon Service status: $logonStatus" -ShowConsole -Color Green } else { Write-BISFLog -Msg "Cache folder already exists at $NewCachePath. No action needed." -ShowConsole -Color Cyan } } catch { Write-BISFLog -Msg "An error occurred: $_" -ShowConsole -Color Red } } End { Add-BISFFinishLine }