Essential Citrix WEM PowerShell Scripts for Workspace Environment Management
A practical guide to automating Citrix Workspace Environment Management (WEM) with PowerShell. Includes ready-to-use scripts for filters, actions, and configuration.
Why Automate WEM with PowerShell?
Citrix Workspace Environment Management (WEM) is powerful for optimizing user environments — drive mappings, printer mappings, registry settings, environment variables, and more. But configuring it through the GUI for hundreds of actions and filters gets tedious fast.
PowerShell automation lets you template configurations, replicate across sites, and maintain consistency. Here are the essential scripts every WEM admin needs.
Connecting to WEM
Before running any WEM PowerShell commands, you need to load the WEM SDK module and connect to your broker:
# Load WEM PowerShell module
Add-PSSnapin Citrix.WEM.SDK
# Connect to WEM infrastructure server
$wemServer = "wem-infra01.corp.local"
New-WEMBrokerConnection -InfrastructureServer $wemServerScript 1: Export All WEM Actions
Back up your entire WEM configuration to a JSON file — invaluable for disaster recovery and environment replication:
# Export all actions from a WEM configuration set
$configSet = Get-WEMConfigurationSet -Name "Production"
$actions = @{
Applications = Get-WEMApplication -ConfigurationSetId $configSet.Id
Printers = Get-WEMPrinter -ConfigurationSetId $configSet.Id
NetDrives = Get-WEMNetDrive -ConfigurationSetId $configSet.Id
RegValues = Get-WEMRegistryEntry -ConfigurationSetId $configSet.Id
EnvVariables = Get-WEMEnvironmentVariable -ConfigurationSetId $configSet.Id
}
$actions | ConvertTo-Json -Depth 5 | Out-File "C:\WEM-Backup\actions-export.json"
Write-Host "Exported $($actions.Values | ForEach-Object { $_.Count } | Measure-Object -Sum | Select-Object -Expand Sum) actions"Script 2: Bulk Create Drive Mappings
Map network drives based on department — a common WEM use case automated:
# Define drive mappings per department
$driveMaps = @(
@{ Name = "Finance Share"; Path = "\\fileserver\finance$"; Letter = "F:"; Filter = "Finance Users" }
@{ Name = "HR Share"; Path = "\\fileserver\hr$"; Letter = "H:"; Filter = "HR Users" }
@{ Name = "Engineering Share"; Path = "\\fileserver\engineering$"; Letter = "E:"; Filter = "Engineering Users" }
@{ Name = "Common Share"; Path = "\\fileserver\common$"; Letter = "S:"; Filter = "Domain Users" }
)
$configSetId = (Get-WEMConfigurationSet -Name "Production").Id
foreach ($drive in $driveMaps) {
$newDrive = New-WEMNetDrive -ConfigurationSetId $configSetId \
-Name $drive.Name \
-TargetPath $drive.Path \
-DriveLetter $drive.Letter \
-State Enabled
# Assign to filter
$filter = Get-WEMFilter -Name $drive.Filter -ConfigurationSetId $configSetId
if ($filter) {
New-WEMAssignment -AssignedObjectId $newDrive.Id \
-FilterId $filter.Id \
-ConfigurationSetId $configSetId
}
Write-Host "Created drive mapping: $($drive.Letter) -> $($drive.Path)"
}Script 3: Create WEM Filters from AD Groups
Automatically create WEM filters for every OU or security group:
# Create WEM filters from AD security groups
$groups = Get-ADGroup -Filter 'Name -like "CTX-*"' -SearchBase "OU=Citrix Groups,DC=corp,DC=local"
$configSetId = (Get-WEMConfigurationSet -Name "Production").Id
foreach ($group in $groups) {
$filterName = $group.Name -replace "CTX-", ""
$existing = Get-WEMFilter -Name $filterName -ConfigurationSetId $configSetId -ErrorAction SilentlyContinue
if (-not $existing) {
New-WEMFilter -Name $filterName \
-ConfigurationSetId $configSetId \
-FilterType ActiveDirectory \
-FilterValue $group.DistinguishedName \
-State Enabled
Write-Host "Created filter: $filterName"
} else {
Write-Host "Filter already exists: $filterName" -ForegroundColor Yellow
}
}Script 4: WEM Health Check
Quick health check for your WEM infrastructure:
# WEM Infrastructure health check
$wemServers = @("wem-infra01", "wem-infra02")
foreach ($server in $wemServers) {
$svc = Get-Service -ComputerName $server -Name "Norskale Infrastructure Service" -ErrorAction SilentlyContinue
$status = if ($svc.Status -eq "Running") { "OK" } else { "DOWN" }
Write-Host "$server : WEM Service = $status" -ForegroundColor $(if ($status -eq "OK") { "Green" } else { "Red" })
}
# Check WEM database connectivity
try {
$configSets = Get-WEMConfigurationSet
Write-Host "WEM Database: OK ($($configSets.Count) configuration sets)" -ForegroundColor Green
} catch {
Write-Host "WEM Database: ERROR - $($_.Exception.Message)" -ForegroundColor Red
}
# Check agent registration count
$agents = Get-WEMRegisteredAgent
Write-Host "Registered agents: $($agents.Count)"Generate Custom WEM Scripts Instantly
Need a WEM script for your specific environment? VDIVibes AI understands WEM configuration sets, filters, actions, and assignments — and generates production-ready PowerShell tailored to your setup.