Script Repository


Remove disk quota for user on the drive where the user's home directory is located

April 06, 2020
1165

This script removes disk quotas for a user on the drive where the user's home directory is located.

To use the script, you need to create a Business Rule triggered automatically once a new user is created or changed. For more information on how to automatically run a script once a new user is created, see Run PowerShell Script after Creating a User.

Edit Remove
PowerShell
$homeDirectoryPath = "%homeDirectory%"
$homeDirectoryPath = $homeDirectoryPath.Replace("\\", "")
$homeDirectoryPathParts = $homeDirectoryPath.Split("\")

# Get disk quota object for the computer where the user's home folder is located
$objQuotas = Get-WMIObject Win32_DiskQuota -ComputerName $homeDirectoryPathParts[0]

$domainName = $Context.GetObjectDomain("%distinguishedName%")
$flatDomainName = $domainName.SubString(0,$domainName.IndexOf("."))

foreach($objQuota in $objQuotas)
{
    # Find disk quotas for the target user
    if($objQuota.User -eq 'Win32_Account.Domain="' + $flatDomainName + '",Name="' + "%username%" + '"')
    {
        $Context.LogMessage("Disk quota deleted for user %username% on the following volume: " + $objQuota.QuotaVolume, "Information")
        $objQuota.Delete()
        return
    }
}

$Context.LogMessage("No disk quota found for user %username% on server " + $homeDirectoryPathParts[0], "Information")


Comments ( 0 )
No results found.
Leave a comment