Knowledge Base

Example: free disk space (Windows)

This Example will describe how to check for free disk space ie. let LazyNanny know that there is ample disk space.
Create a scheduled trigger that will check for free disk space. Lets assume you want more than '5GB' free disk space for C: your drive.

Create a powershell script with following content

# LazyNanny free disk space example
# Script will stop sending "I'm OK" messages to LazyNanny if not enough free disk space.
# command: powershell -ExecutionPolicy ByPass c:\lazynanny\lazynanny.ps1 <servername> <object_id> [<drive> <free space>]

$server=$args[0]                           <# required, servername #>
$object_id=$args[1]                        <# required, object_id  #>
$drive='C:'                                <# default drive #>
$freespace='5GB'                           <# default minimal free disk space #>

if(!$server -or !$object_id){
  echo "Missing servername and/or object_id" | Out-File $PSScriptRoot\lazynanny.log
  exit 1                                   <# missing servername and/or object_id #>

if($args[2]){$drive=$args[2]}              <# optional drive #>
if($args[3]){$freespace=$args[3]}          <# optional minimal free space #>

$result='Not enough free space'
  if(Get-WmiObject Win32_logicaldisk|Select *|where DeviceID -eq "$drive"|where freespace -gt "$freespace"){
    $cli=New-Object System.Net.WebClient
$result | Out-File $PSScriptRoot\lazynanny.log  <# log last result #>

Save this script as eg. c:\lazynanny\lazynanny.ps1.

Windows Task Scheduler
Create a scheduled task to run script every 5 minutes

  1. Start your Windows Command Prompt as Administrator.
    From the Windows menu search for "cmd",
    right-click on "Command Prompt" to select "Run as administrator"
    Command Prompt as Administrator.

  2. Run the command below to create a LazyNanny scheduled trigger. Do not forget to
    • change server ie. tip2027def to point to your server
    • change the object_id ie. 3348ivf3go-8016-660 with your Object ID
    • optional: change the drive name 'C:' or freespace '5GB' to your requirements
command format: powershell -ExecutionPolicy ByPass c:\lazynanny\lazynanny.ps1 <servername> <object_id> [<drive> <free space>]  
Note: <drive> and <free space> are optional.

schtasks.exe /create /tn LazyNanny /sc minute /mo 5 /ru system /tr "powershell -ExecutionPolicy ByPass c:\lazynanny\lazynanny.ps1 tip2027def 3348ivf3go-8016-660"

Command Prompt as Administrator

Every 5 minutes the LazyNanny scheduler will start sending "I'm OK" messages to your selected* LazyNanny server (eg. That is, as long as there is more than 5GB of free disk space. If less; the scheduler will stop sending "I'm OK" messages to your LazyNanny server. This will make LazyNanny™ nervous and it will start sending notifications to your (list of) Recipients*.

*Free products Recipients default to account email address and default server location

Please rate this article to help us improve our Knowledge Base.

0 0