File Server: Crear Cuotas en Windows Server 2012 R2 con Powershell

Recientemente he tenido que asignar cuotas a un buen numero de recursos en Windows Server 2012 R2, que una vez añadido el rol de File Server incluye un modulo powershell para gestionar las cuotas y deja obsoleto al comando dirquota.exe.

import-module FileServerResourceManager

En mi caso eran shares con tamaño muy distinto, bueno, ni siquiera sabia el tamaño exacto y queria darles 3 GB mas de margen.
Una buena (y rapida) forma de saber el tamaño del recurso es crear una cuota de tipo SOFT de un tamaño cualquiera:
new-fsrmquota -path $ruta -size 1GB -softlimit
Despues consultamos la información de la cuota y sumamos 3GB de margen:
$sizeinbytes=(get-fsrmquota -path $ruta).usage
$newsizeinbytes=$sizeinbytes+(3 * 1073741824)
Y cambiamos la cuota a tipo HARD y establecemos el tamaño definitivo:
set-fsrmquota -path $ruta -size $newsizeinbytes -softlimit:$false
He hecho un pequeño script con menu para generar las cuotas facilmente:
Function crear-soft()
{
$ruta=read-host "Path a crear nueva Quota?"
$currentquota=get-fsrmquota -path $ruta -erroraction silentlycontinue
 if ($currentquota -ne $null)
 {
 write-host "Ya existe una Quota para esta ruta!" -fore yellow
 $currentquota|ft PSComputerName,path,disabled,softLimit
 }
 else
 {
 new-fsrmquota -path $ruta -size 1GB -softlimit
 }
}#fin crear-soft
Function crear-softfromshares()
{
$arrayshares=gwmi Win32_share|?{$_.path.length -gt 3}
$arrayQuotas=(get-fsrmquota).path

#listo los shares existentes que no tienen cuota definida
$selected=$arrayshares|?{$arrayQuotas -notcontains $_.path}|select PSComputername,name,path|out-gridview -passthru -title "Selecciona SOFT QUOTAS a crear"
 if ($selected -eq $null){write-host "Ninguno seleccionado" -fore yellow}
 else{$selected|%{new-fsrmquota -path $_.path -size 1GB -softlimit}}
}#fin crear-softfromshares

Function crear-hard()
{
$array=get-fsrmquota |?{$_.softlimit -eq $true}

$selected=$array|select PSComputerName,path,usage|out-gridview -passthru -title "Selecciona Quotas a activar"
 if ($selected -eq $null){write-host "Ninguno seleccionado" -fore yellow}
 else
 {
 $selected|%{
  $newsizeinbytes=$_.usage+(3 * 1073741824)# ampliacion de 3 GB al tamaño actual
  set-fsrmquota -path $_.path -size $newsizeinbytes -softlimit:$false  
  #comprobamos los cambios
  get-fsrmQuota -path $_.path|%{  
  $sizeGBactual = "{0:0.0}GB" -f ($_.size/1GB)
  write-host "Current Quota of $($_.path) is $sizeGBactual" -fore cyan
  }
  }
 }
}#fin crear-hard

### main ###
import-module FileServerResourceManager
do
{
write-host "THE QUOTA MAKER" -fore cyan
write-host "  1. CREAR NUEVA SOFT QUOTA MANUALMENTE" -fore cyan
write-host "  2. CREAR NUEVA SOFT QUOTA DESDE LISTA DE SHARES" -fore cyan
write-host "  3. MIGRAR SOFT QUOTA A HARD QUOTA" -fore cyan
write-host "  0. Exit" -fore cyan
$val=read-host "Elige una opcion"
 switch ($val)
 {
 1{crear-soft}
 2{crear-softfromshares}
 3{crear-hard}
 }
}
while ($val -ne "0")

Comentarios