Citrix XenApp – List servers publishing no applications

List servers and number of published applications.

MFCOM/.vbs:
set farm = CreateObject("MetaFrameCOM.MetaFrameFarm")
farm.Initialize(1)
for each server in farm.Servers
if server.Applications.Count = 0 then
WScript.Echo server.ServerName & " " & server.Applications.Count
end if
next

PowerShell:
Add-PSSnapin Citrix.XenApp.Commands
Get-XAServer | Select ServerName, @{n='Applications'; e={$_ | Get-XAApplication | Measure-Object | Select -Expand Count}}

Run Internet Explorer in a loop

@echo off
set zm=1
start "" /b /wait "C:\Program Files\Internet Explorer\iexplore.exe"
:loop
tasklist | find /i "iexplore" > nul
if %errorlevel% neq 0 start "" /b /wait "C:\Program Files\Internet Explorer\iexplore.exe"
if %zm% GTR 0 goto loop

List sessions in Citrix XenApp 4.5 sample script

<package><job id="Discovery"><reference object="MetaFrameCOM.MetaFrameFarm"/>
<reference object="MetaFrameCOM.MetaFramePolicy"/><script language="VBScript">
Dim theFarm : Set theFarm = WScript.CreateObject("MetaFrameCOM.MetaFrameFarm")
theFarm.Initialize(MetaFrameWinFarmObject)
Wscript.Echo "Sessions on a farm: " & theFarm.FarmName


For Each aSession in theFarm.Sessions
if aSession.AppName <> "" then
Wscript.Echo aSession.SessionName & " " & aSession.AppName & " " & aSession.ClientName
end if
Next
</script></job></package>

Save the script as a .wsh file and run using cscript:
cscript scriptname.wsh

Free disk space script

@echo off
rem set SPACE_LIMIT=200
set /p SPACE_LIMIT=Limit:

for /f “tokens=3” %%i in (‘”dir c: /-c | find /i “bytes free””‘) do set TSPACE=%%i
set FREE_SPACE=%TSPACE:~0,-6%
if %FREE_SPACE% GTR %SPACE_LIMIT% (
echo %FREE_SPACE% ^> %SPACE_LIMIT%
) else (
echo %FREE_SPACE% ^< %SPACE_LIMIT%
)

Script drops last six digits from ‘total bytes free’ line of dir command because of cmd.exe 32-bit integer limitation so a comparision is done using megabytes.