Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; reboot on logoff if the writecache is full
- ; by james trevaskis
- ; 26/07/2012
- ; version 0.03
- ;vars
- ;target write cache in mb - currently 750mb
- $writecachet = 750
- ;write cache drive letter
- $writecached = d:\
- ;debug
- $debug=1
- $serverlogpath="\\network.local\citrix_writecachemonitor.log"
- ;main
- ;get current free space
- $freespaceraw=diskspace($writecached, 1)
- ;convert freespace to int
- $freespacearray = split($freespaceraw, ".")
- $freespace = $freespacearray[0]
- ;debug
- if ($debug)
- ? " "
- ? "debug mode"
- ? " "
- ? " target freespace - " $writecachet
- ? "current freespace - " $freespace
- ? " "
- endif
- ;evaluate freespace
- if ($writecachet > $freespace)
- $debugOutput = "Write cache size is currently $freespace, less than the desired value, rebooting..."
- debugOut($debugOutput)
- shutdown("", "System is being rebooted to flush write cache", 10, 1, 1)
- else
- $debugOutput = "Write cache size is currently $freespace, within acceptable limits..."
- debugOut($debugOutput)
- endif
- :EOF
- exit
- ;functions
- ;debug output
- function debugOut($command)
- if ($debug)
- ? $command
- shell '%comspec% /c echo @DATE @TIME : Citrix Logoff Event : User @USERID , workstation @WKSTA - $command >>$ServerLogPath'
- endif
- endfunction
- ;thanks to Jens Meyer for the diskspace function
- function diskspace(optional $drive, optional $format)
- dim $objWMIService, $sWQL, $colDrives, $objDrive
- if not $drive
- $drive='%WINDIR%'
- endif
- $format=val($format)
- if $format<5
- $format=iif($format=1,1024,iif($format=2,1024.0*1024,iif($format=3,1024.0*1024*1024,iif($format=4,1024.0*1024*1024*1024,1))))
- $diskspace=cdbl(GETDISKSPACE($drive))/$format
- else
- $objWMIService=getobject('winmgmts:{impersonationLevel=impersonate}!\\'+@WKSTA+'\root\cimv2')
- $sWQL = "SELECT Size, FreeSpace FROM Win32_LogicalDisk WHERE Name='"+left($drive,2)+"'"
- $colDrives=$objWMIService.ExecQuery($sWQL)
- for each $objDrive in $colDrives
- $diskspace=cdbl($objDrive.FreeSpace)/cdbl($objDrive.Size)*100
- next
- endif
- exit @ERROR
- endfunction
Add Comment
Please, Sign In to add comment