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.
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")