########################################################### # Script to check the size and free space of share ########################################################### ########################################################### # Version Information ########################################################### # $LastChangedDate: $ # $Rev: 1 $ # #By: Massimiliano De Cò ########################################################### ########################################################### # Activate Snap-In Functionality ########################################################### ########################################################### # Handle Command Line Arguments # Expected: $arg1name="-uncpath" $arg2name="-threshold" ########################################################### $argument1 = "" $argument2 = 0.4 #default if($args[0] -ne '-logfile') { trap { Write-Host "Error: Invalid Arguments" Exit 1 } For ($i=0; $i -lt $args.Count; $i++) { if ( $args[$i] -eq $arg1name ) { $argument1= $args[$i + 1] } if ( $args[$i] -eq $arg2name ) { $argument2= [double]$args[$i + 1] } } } else { Write-Host "Error: Invalid Arguments"; Exit 1; } if ( $argument1 -eq "" ) { Write-Host "Error: Invalid Arguments"; Exit 1; } if ( $argument2-lt 0 ) { Write-Host "Error: Invalid Arguments"; Exit 1; } $uncpath=$argument1 $threshold=$argument2 ########################################################### # Perform Script Operations ########################################################### # $uncpath="\\FRITZ\fritz" try { $Size = (New-Object -ComObject Scripting.FileSystemObject).getdrive($uncpath) } catch { Write-Host $uncpath + " error - not found" Exit 1 } $Total="{0:n2} GB" -f ($size.totalsize / 1GB) $freespace=($size.FreeSpace / 1GB) $Free="{0:n2} GB" -f ($freespace) IF ($freeSpace -gt $threshold) { Write-Host "OK $uncpath Free space: $Free > $threshold GB - Total Size: $total" Exit 0 } else { Write-Host "KO $uncpath Free space: $Free <= $threshold GB - Total Size: $total" Exit 0 }