<#
.SYNOPSIS
File Share Quota Manager v1.1
.DESCRIPTION
Menu enabled quota manager. Leverages the FSRM dirquota command line tool.
Requires PSRemoting enabled on target servers.
Functions:
1. Adds New Quota
-Creates a new quota using standard user share template
2. Shows Quota & Local Drive Information
-Shows common quota parameters & local disk information
-Shows information (free space) for all available local disks (load balancing purposes)
3. Modifies Existing Quota
-Modifies the Quota Limit
-Applies New Standard Templates:
*User Predefined:
*4 GB User Share Hard Quota
*8 GB User Share Hard Quota
*12 GB User Share Hard Quota
*16 GB User Share Hard Quota
*20 GB User Share Hard Quota
*4 GB User Limit with 250 MB Extension
*8 GB User Limit with 250 MB Extension
*12 GB User Limit with 250 MB Extension
*16 GB User Limit with 250 MB Extension
*20 GB User Limit with 250 MB Extension
*Groups Predefined:
*10 GB Group Share Hard Quota
*20 GB Group Share Hard Quota
*30 GB Group Share Hard Quota
*40 GB Group Share Hard Quota
*50 GB Group Share Hard Quota
*10 GB Group Limit with 250 MB Extension
*20 GB Group Limit with 250 MB Extension
*30 GB Group Limit with 250 MB Extension
*40 GB Group Limit with 250 MB Extension
*50 GB Group Limit with 250 MB Extension
-Disables Quota
-Enables Quota
.NOTES
File Name : quota-mgr.ps1
Author: Nikolay Petkov
http://77.104.138.174/~powershe/power-shell.com
#>
$sharename = Read-Host "Share Name"
$virtualname = Read-Host "Server Name"
Write-host "Please Wait..."
#HOSTNAME vs. VIRTUAL SERVER NAME
$servername = $virtualname #Comment out if your input is a virtual server name.
#Uncomment the following line if your input is a virtual server name. It will resolve the server's hostname and add the DNS suffix.
#$servername = (get-wmiobject Win32_computersystem -computername $virtualname).DNSHostname + ".yourdomain.com"
#MAIN MENU
do {
[int]$xMenuChoiceA = 0
while ( $xMenuChoiceA -lt 1 -or $xMenuChoiceA -gt 5 ){
Write-Host “`t`tFile Share Quota Manager Version 1.1`n” -ForegroundColor Cyan
Write-host "`t`t`t-MAIN MENU- $sharename" -Foregroundcolor GREEN
Write-host "`t`t1. Show Quota & Local Drive Information"
Write-host "`t`t2. Modify Existing Quota"
Write-host "`t`t3. Add New Quota"
Write-host "`t`t4. Get Help"
Write-host "`t`t5. Quit"
[Int]$xMenuChoiceA = read-host "`nPlease enter an option 1 to 5..." }
#MAIN MENU - Show Quota & Local Drive Information
Switch( $xMenuChoiceA ){
1{
Invoke-Command -ComputerName $servername -ScriptBlock {
param(
$servername,$sharename,$virtualname
)
$localpath = Get-WmiObject win32_share -ComputerName $servername | Where-Object {$_.name -match "$sharename"} | select -ExpandProperty path
dirquota q l /p:$localpath
Write-Host "Local Disk Information for $sharename"
Get-WmiObject -Class win32_logicaldisk -ComputerName $servername -Filter "DriveType=3" | where { $localpath -Like "$($_.Name)*" } | Select-Object -Property @{Name = 'DriveLetter'; Expression = {$_.DeviceID}}, VolumeName, @{n='Size';e={"{0:F2} GB" -f ($_.Size / 1gb)}}, @{n='FreeSpace';e={"{0:F2} GB" -f ($_.FreeSpace / 1gb)}} | Format-Table -AutoSize
Write-Host "Possible New Location on $virtualname"
Get-WmiObject -Class win32_logicaldisk -ComputerName $servername -Filter "DriveType=3" | where { $localpath -notLike "$($_.Name)*" -and $_.Name -notLike "C*" -and $_.Name -notLike "D*" -and $_.Name -notLike "Q*"} | Select-Object -Property @{Name = 'DriveLetter'; Expression = {$_.DeviceID}}, VolumeName, @{n='Size';e={"{0:F2} GB" -f ($_.Size / 1gb)}}, @{n='FreeSpace';e={"{0:F2} GB" -f ($_.FreeSpace / 1gb)}} | Format-Table -AutoSize
} -argumentlist $servername,$sharename,$virtualname | out-host -paging
}
#-MENU MODIFY EXISTING QUOTA
2{[int]$xMenuChoiceA = 0
while ( $xMenuChoiceA -lt 1 -or $xMenuChoiceA -gt 5 ){
Write-host "`t`t`t-MODIFY EXISTING QUOTA- $sharename" -Foregroundcolor GREEN
Write-host "`t`t1. Modify the Quota Limit"
Write-host "`t`t2. Apply New Standard Template"
Write-host "`t`t3. Disable Quota"
Write-host "`t`t4. Enable Quota"
Write-host "`t`t5. <-- Go to Main Menu"
[Int]$xMenuChoiceA = read-host "`nPlease enter an option 1 to 5..."}
#Modify the Quota Limit
Switch( $xMenuChoiceA ){
1{
Write-Host "`t`t`t-MODIFY THE QUOTA LIMIT- $sharename" -Foregroundcolor GREEN
$NewLimit = Read-Host "Enter New Limit(GB)"
Invoke-Command -ComputerName $servername -ScriptBlock {
param(
$servername,$sharename,$NewLimit
)
$localpath = Get-WmiObject win32_share -ComputerName $servername | Where-Object {$_.name -match "$sharename"} | select -ExpandProperty path
$ModifyLimit = dirquota q m /p:$localpath /limit:$NewLimit"GB"
$ModifyLimit
Write-Host "Quota Limit Modified Successfully to $NewLimit"GB"" -Foregroundcolor GREEN
dirquota q l /p:$localpath
} -argumentlist $servername,$sharename,$NewLimit
}
#--MODIFY EXISTING QUOTA MENU - APPLY NEW STANDARD TEMPLATE
2{[int]$xMenuChoiceA = 0
while ( $xMenuChoiceA -lt 1 -or $xMenuChoiceA -gt 3 ){
Write-host "`t`t`t-APPLY NEW AT&T STANDARD TEMPLATE- $sharename" -Foregroundcolor GREEN
Write-host "`t`t1. User Standard Templates"
Write-host "`t`t2. Group Share Standard Templates"
Write-host "`t`t3. <-- Go to Main Menu"
[Int]$xMenuChoiceA = read-host "`nPlease enter an option 1 to 3..." }
#---MODIFY EXISTING QUOTA MENU - APPLY NEW AT&T STANDARD TEMPLATE - USER STANDARD TEMPLATES
Switch( $xMenuChoiceA ){
1{[int]$xMenuChoiceA = 0
while ( $xMenuChoiceA -lt 1 -or $xMenuChoiceA -gt 11 ){
Write-host "`t`t`t-USER STANDARD TEMPLATES- $sharename" -Foregroundcolor GREEN
Write-host "`t`t1. 4 GB User Share Hard Quota"
Write-host "`t`t2. 8 GB User Share Hard Quota"
Write-host "`t`t3. 12 GB User Share Hard Quota"
Write-host "`t`t4. 16 GB User Share Hard Quota"
Write-host "`t`t5. 20 GB User Share Hard Quota"
Write-host "`t`t6. 4 GB User Limit with 250 MB Extension"
Write-host "`t`t7. 8 GB User Limit with 250 MB Extension"
Write-host "`t`t8. 12 GB User Limit with 250 MB Extension"
Write-host "`t`t9. 16 GB User Limit with 250 MB Extension"
Write-host "`t`t10. 20 GB User Limit with 250 MB Extension"
Write-host "`t`t11. <-- Go to Main Menu"
[Int]$xMenuChoiceA = read-host "`nPlease enter an option 1 to 11..." }
Switch( $xMenuChoiceA ){
1{
Invoke-Command -ComputerName $servername -ScriptBlock {
param(
$servername,$sharename,$NewLimit
)
$localpath = Get-WmiObject win32_share -ComputerName $servername | Where-Object {$_.name -match "$sharename"} | select -ExpandProperty path
dirquota q m /p:$localpath /sourcetemplate:"4 GB User Share Hard Quota"
dirquota q l /p:$localpath
} -argumentlist $servername,$sharename
}
2{Invoke-Command -ComputerName $servername -ScriptBlock {
param(
$servername,$sharename,$NewLimit
)
$localpath = Get-WmiObject win32_share -ComputerName $servername | Where-Object {$_.name -match "$sharename"} | select -ExpandProperty path
dirquota q m /p:$localpath /sourcetemplate:"8 GB User Share Hard Quota"
dirquota q l /p:$localpath
} -argumentlist $servername,$sharename}
3{Invoke-Command -ComputerName $servername -ScriptBlock {
param(
$servername,$sharename,$NewLimit
)
$localpath = Get-WmiObject win32_share -ComputerName $servername | Where-Object {$_.name -match "$sharename"} | select -ExpandProperty path
dirquota q m /p:$localpath /sourcetemplate:"12 GB User Share Hard Quota"
dirquota q l /p:$localpath
} -argumentlist $servername,$sharename}
4{Invoke-Command -ComputerName $servername -ScriptBlock {
param(
$servername,$sharename,$NewLimit
)
$localpath = Get-WmiObject win32_share -ComputerName $servername | Where-Object {$_.name -match "$sharename"} | select -ExpandProperty path
dirquota q m /p:$localpath /sourcetemplate:"16 GB User Share Hard Quota"
dirquota q l /p:$localpath
} -argumentlist $servername,$sharename}
5{Invoke-Command -ComputerName $servername -ScriptBlock {
param(
$servername,$sharename,$NewLimit
)
$localpath = Get-WmiObject win32_share -ComputerName $servername | Where-Object {$_.name -match "$sharename"} | select -ExpandProperty path
dirquota q m /p:$localpath /sourcetemplate:"20 GB User Share Hard Quota"
dirquota q l /p:$localpath
} -argumentlist $servername,$sharename}
6{Invoke-Command -ComputerName $servername -ScriptBlock {
param(
$servername,$sharename,$NewLimit
)
$localpath = Get-WmiObject win32_share -ComputerName $servername | Where-Object {$_.name -match "$sharename"} | select -ExpandProperty path
dirquota q m /p:$localpath /sourcetemplate:"4 GB User Limit with 250 MB Extension"
dirquota q l /p:$localpath
} -argumentlist $servername,$sharename}
7{Invoke-Command -ComputerName $servername -ScriptBlock {
param(
$servername,$sharename,$NewLimit
)
$localpath = Get-WmiObject win32_share -ComputerName $servername | Where-Object {$_.name -match "$sharename"} | select -ExpandProperty path
dirquota q m /p:$localpath /sourcetemplate:"8 GB User Limit with 250 MB Extension"
dirquota q l /p:$localpath
} -argumentlist $servername,$sharename}
8{Invoke-Command -ComputerName $servername -ScriptBlock {
param(
$servername,$sharename,$NewLimit
)
$localpath = Get-WmiObject win32_share -ComputerName $servername | Where-Object {$_.name -match "$sharename"} | select -ExpandProperty path
dirquota q m /p:$localpath /sourcetemplate:"12 GB User Limit with 250 MB Extension"
dirquota q l /p:$localpath
} -argumentlist $servername,$sharename}
9{Invoke-Command -ComputerName $servername -ScriptBlock {
param(
$servername,$sharename,$NewLimit
)
$localpath = Get-WmiObject win32_share -ComputerName $servername | Where-Object {$_.name -match "$sharename"} | select -ExpandProperty path
dirquota q m /p:$localpath /sourcetemplate:"16 GB User Limit with 250 MB Extension"
dirquota q l /p:$localpath
} -argumentlist $servername,$sharename}
10{Invoke-Command -ComputerName $servername -ScriptBlock {
param(
$servername,$sharename,$NewLimit
)
$localpath = Get-WmiObject win32_share -ComputerName $servername | Where-Object {$_.name -match "$sharename"} | select -ExpandProperty path
dirquota q m /p:$localpath /sourcetemplate:"20 GB User Limit with 250 MB Extension"
dirquota q l /p:$localpath
} -argumentlist $servername,$sharename}
}
}
#---MODIFY EXISTING QUOTA MENU - APPLY NEW STANDARD TEMPLATE - GROUP SHARE STANDARD TEMPLATES
2{[int]$xMenuChoiceA = 0
while ( $xMenuChoiceA -lt 1 -or $xMenuChoiceA -gt 11 ){
Write-host "`t`t`t-GROUP SHARE STANDARD TEMPLATES- $sharename" -Foregroundcolor GREEN
Write-host "`t`t1. 10 GB Group Share Hard Quota"
Write-host "`t`t2. 20 GB Group Share Hard Quota"
Write-host "`t`t3. 30 GB Group Share Hard Quota"
Write-host "`t`t4. 40 GB Group Share Hard Quota"
Write-host "`t`t5. 50 GB Group Share Hard Quota"
Write-host "`t`t6. 10 GB Group Limit with 250 MB Extension"
Write-host "`t`t7. 20 GB Group Limit with 250 MB Extension"
Write-host "`t`t8. 30 GB Group Limit with 250 MB Extension"
Write-host "`t`t9. 40 GB Group Limit with 250 MB Extension"
Write-host "`t`t10. 50 GB Group Limit with 250 MB Extension"
Write-host "`t`t11. <-- Go to Main Menu"
[Int]$xMenuChoiceA = read-host "`nPlease enter an option 1 to 11..." }
Switch( $xMenuChoiceA ){
1{
Invoke-Command -ComputerName $servername -ScriptBlock {
param(
$servername,$sharename,$NewLimit
)
$localpath = Get-WmiObject win32_share -ComputerName $servername | Where-Object {$_.name -match "$sharename"} | select -ExpandProperty path
dirquota q m /p:$localpath /sourcetemplate:"10 GB Group Share Hard Quota"
dirquota q l /p:$localpath
} -argumentlist $servername,$sharename
}
2{Invoke-Command -ComputerName $servername -ScriptBlock {
param(
$servername,$sharename,$NewLimit
)
$localpath = Get-WmiObject win32_share -ComputerName $servername | Where-Object {$_.name -match "$sharename"} | select -ExpandProperty path
dirquota q m /p:$localpath /sourcetemplate:"20 GB Group Share Hard Quota"
dirquota q l /p:$localpath
} -argumentlist $servername,$sharename}
3{Invoke-Command -ComputerName $servername -ScriptBlock {
param(
$servername,$sharename,$NewLimit
)
$localpath = Get-WmiObject win32_share -ComputerName $servername | Where-Object {$_.name -match "$sharename"} | select -ExpandProperty path
dirquota q m /p:$localpath /sourcetemplate:"30 GB Group Share Hard Quota"
dirquota q l /p:$localpath
} -argumentlist $servername,$sharename}
4{Invoke-Command -ComputerName $servername -ScriptBlock {
param(
$servername,$sharename,$NewLimit
)
$localpath = Get-WmiObject win32_share -ComputerName $servername | Where-Object {$_.name -match "$sharename"} | select -ExpandProperty path
dirquota q m /p:$localpath /sourcetemplate:"40 GB Group Share Hard Quota"
dirquota q l /p:$localpath
} -argumentlist $servername,$sharename}
5{Invoke-Command -ComputerName $servername -ScriptBlock {
param(
$servername,$sharename,$NewLimit
)
$localpath = Get-WmiObject win32_share -ComputerName $servername | Where-Object {$_.name -match "$sharename"} | select -ExpandProperty path
dirquota q m /p:$localpath /sourcetemplate:"50 GB Group Share Hard Quota"
dirquota q l /p:$localpath
} -argumentlist $servername,$sharename}
6{Invoke-Command -ComputerName $servername -ScriptBlock {
param(
$servername,$sharename,$NewLimit
)
$localpath = Get-WmiObject win32_share -ComputerName $servername | Where-Object {$_.name -match "$sharename"} | select -ExpandProperty path
dirquota q m /p:$localpath /sourcetemplate:"10 GB Group Limit with 250 MB Extension"
dirquota q l /p:$localpath
} -argumentlist $servername,$sharename}
7{Invoke-Command -ComputerName $servername -ScriptBlock {
param(
$servername,$sharename,$NewLimit
)
$localpath = Get-WmiObject win32_share -ComputerName $servername | Where-Object {$_.name -match "$sharename"} | select -ExpandProperty path
dirquota q m /p:$localpath /sourcetemplate:"20 GB Group Limit with 250 MB Extension"
dirquota q l /p:$localpath
} -argumentlist $servername,$sharename}
8{Invoke-Command -ComputerName $servername -ScriptBlock {
param(
$servername,$sharename,$NewLimit
)
$localpath = Get-WmiObject win32_share -ComputerName $servername | Where-Object {$_.name -match "$sharename"} | select -ExpandProperty path
dirquota q m /p:$localpath /sourcetemplate:"30 GB Group Limit with 250 MB Extension"
dirquota q l /p:$localpath
} -argumentlist $servername,$sharename}
9{Invoke-Command -ComputerName $servername -ScriptBlock {
param(
$servername,$sharename,$NewLimit
)
$localpath = Get-WmiObject win32_share -ComputerName $servername | Where-Object {$_.name -match "$sharename"} | select -ExpandProperty path
dirquota q m /p:$localpath /sourcetemplate:"40 GB Group Limit with 250 MB Extension"
dirquota q l /p:$localpath
} -argumentlist $servername,$sharename}
10{Invoke-Command -ComputerName $servername -ScriptBlock {
param(
$servername,$sharename,$NewLimit
)
$localpath = Get-WmiObject win32_share -ComputerName $servername | Where-Object {$_.name -match "$sharename"} | select -ExpandProperty path
dirquota q m /p:$localpath /sourcetemplate:"50 GB Group Limit with 250 MB Extension"
dirquota q l /p:$localpath
} -argumentlist $servername,$sharename}
}
}
}
}
#--MODIFY EXISTING QUOTA MENU - Disable Quota
3{
Invoke-Command -ComputerName $servername -ScriptBlock {
param(
$servername,$sharename
)
$localpath = Get-WmiObject win32_share -ComputerName $servername | Where-Object {$_.name -match "$sharename"} | select -ExpandProperty path
dirquota q m /p:$localpath /status:disabled
dirquota q l /p:$localpath
} -argumentlist $servername,$sharename}
#--MODIFY EXISTING QUOTA MENU - Enable Quota
4. {
Invoke-Command -ComputerName $servername -ScriptBlock {
param(
$servername,$sharename
)
$localpath = Get-WmiObject win32_share -ComputerName $servername | Where-Object {$_.name -match "$sharename"} | select -ExpandProperty path
dirquota q m /p:$localpath /status:enabled
dirquota q l /p:$localpath
} -argumentlist $servername,$sharename}
}
}
#MAIN MENU - Add New Quota
3{[int]$xMenuChoiceA = 0
while ( $xMenuChoiceA -lt 1 -or $xMenuChoiceA -gt 3 ){
Write-host "`t`t`t-ADD NEW QUOTA- $sharename" -Foregroundcolor GREEN
Write-host "`t`t1. Create New User Quota (4 GB User Share Hard Quota Template)"
Write-host "`t`t2. Create New Group Share Quota (10 GB Group Share Hard Quota)"
Write-host "`t`t3. <-- Go to Main Menu"
[Int]$xMenuChoiceA = read-host "`nPlease enter an option 1 to 3..." }
Switch( $xMenuChoiceA ){
1{Invoke-Command -ComputerName $servername -ScriptBlock {
param(
$servername,$sharename
)
$localpath = Get-WmiObject win32_share -ComputerName $servername | Where-Object {$_.name -match "$sharename"} | select -ExpandProperty path
dirquota q a /p:$localpath /sourcetemplate:"4 GB User Share Hard Quota"
Write-Host "Quota created with the standard template: 4 GB User Share Hard Quota" -Foregroundcolor GREEN
dirquota q l /p:$localpath
} -argumentlist $servername,$sharename}
2{Invoke-Command -ComputerName $servername -ScriptBlock {
param(
$servername,$sharename
)
$localpath = Get-WmiObject win32_share -ComputerName $servername | Where-Object {$_.name -match "$sharename"} | select -ExpandProperty path
dirquota q a /p:$localpath /sourcetemplate:"10 GB Group Share Hard Quota"
Write-Host "Quota created with the standard template: 10 GB Group Share Hard Quota" -Foregroundcolor GREEN
dirquota q l /p:$localpath
} -argumentlist $servername,$sharename}
}
}
4{
[System.Diagnostics.Process]::Start("http://power-shell.com/2014/powershell-scripts/file-share-quota-manager-tool-menu-based/")
}
}
} while ( $xMenuChoiceA -ne 5 )