Citrix PVS: Measure RAM Cache Usage

When you want to get a quick overview of the RAM write cache usage of your target devices you can use the following PowerShell script.

1. If not done already, allow running unsigned scripts:

Set-ExecutionPolicy RemoteSigned

2. Install the MCLI PowerShell snapin:

$installutil = $env:systemroot + ‘Microsoft.NETFramework64v2.0.50727installutil.exe’
&$installutil McliPSSnapIn.dll

3. Add the MCLI snapin to your PowerShell environment:

 Add-PSSnapin -Name McliPSSnapIn

4. Run the following PowerShell script on your PVS server:

function get-value{
param([string]$strText=””,[string]$strDelimiter=””)
return $strText.SubString($strText.IndexOf($strDelimiter)+2)
}
function get-name{
param([string]$strText=””,[string]$strDelimiter=””)
return $strText.SubString(0,$strText.IndexOf($strDelimiter))
}
Add-PSSnapin McliPS* -ErrorAction SilentlyContinue
$all = @()
$obj = New-Object System.Collections.ArrayList
$lines = Mcli-Get DeviceInfo -f ServerName,`
ServerIpConnection,`
DeviceName,`
SiteName,`
CollectionName,`
Active,`
Status,`
diskLocatorName
for($i=0;$i -lt $lines.length;$i++){
if(($lines[$i].length -gt 0) -and ($lines[$i].contains(“:”)) -and -not ($lines[$i] -match “Executing: Get “)){
$name = get-name -strText $lines[$i] -strDelimiter “:”
$value = get-value -strText $lines[$i] -strDelimiter “:”
if ($name -eq “status” -and $value.Length -le 0){
$value = “0”
}
if ($value.Contains(“,”) -and $name -eq “status”){
$obj | Add-Member -membertype noteproperty -name $name -Value $value.Split(“,”)[1]
}else{
$obj | Add-Member -membertype noteproperty -name $name -Value $value
}
}
if($lines[$i].contains(“#”) -or (($i+1) -eq $lines.length)){
$all += $obj
$obj = New-Object psObject
}
}

$all | Where-Object -FilterScript { ([int] $_.status -gt “0”) -and ([int]$_.status -le “100”) } | Sort-Object {[int] $_.status} -descending | Format-Table @{Expression={$_.deviceName};Label=”Device”}, @{Expression={$_.status};Label=”RAM Cache Used (%)”} -autosize

Thanks to ctxfarmer for providing the base of the script.