We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.

Script Repository

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

February 18, 2021 Views: 2644

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
Leave a comment
Loading...

Got questions?

Support Questions & Answers