rookie_b
asked on
Parse dirquota output in PowerShell
I am having to use dirquota to collect quota information from a number of servers, as FSRM Powershell is not an option. I need to somehow parse the output for a;l properties to a csv file
How do I do that?
Here is an example:
How do I do that?
Here is an example:
dirquota q l /remote:server /path:D:\...
And here is the output it produces:Quota Path: D:\parent\folder1
Description: None
Share Path: \\server\share\folder1
Source Template: 1 TB Limit Reports to User (Matches template)
Quota Status: Enabled
Limit: 1.00 TB (Hard)
Used: 160.92 GB (16%)
Available: 863.08 GB
Peak Usage: 160.92 GB (05/07/2020 16:10)
Thresholds:
Warning ( 85%): E-mail, Report
Limit (100%): E-mail, Report
Quota Path: D:\parent\folder2
Description: None
Share Path: \\server\share\folder2
Source Template: 1 TB Limit Reports to User (Matches template)
Quota Status: Enabled
Limit: 1.00 TB (Hard)
Used: 14.63 GB (1%)
Available: 1,009.37 GB
Peak Usage: 17.34 GB (25/07/2020 09:18)
Thresholds:
Warning ( 85%): E-mail, Report
Limit (100%): E-mail, Report
ASKER
Thanks for responding David,
I tried this but all I got was a single column with a header called "Length"and a long string of numbers below it. I think I might need to somehow filter the headers and their values and pass them on as properties before I can export it as a csv.
I tried this but all I got was a single column with a header called "Length"and a long string of numbers below it. I think I might need to somehow filter the headers and their values and pass them on as properties before I can export it as a csv.
This tool is deprecated and may be removed in future releases of Windows. Please use the Windows PowerShell cmdlets in the FileServerResourceManager module to administer File Server Resource Manager functionality.
why can't you use the PowerShell FRSM module?
why can't you use the PowerShell FRSM module?
ASKER
Server 2008R2 servers, so not supported out of the box. Not sure if it can be addded, but I am not supposed to install anything or make any changes.
Windows Server 2008R2 is no longer supported.. as of January 2020. Time to upgrade.. Right now the company's data is at risk.
Try this:
$Server = 'server'
$DirquotaPath = 'D:\'
$CsvPath = "C:\Temp\DirQuota_$($Server).csv"
$dtProvider = New-Object -TypeName System.Globalization.CultureInfo -ArgumentList 'en-GB'
$out = $null
& dirquota.exe quota list /remote:$Server /path:$DirquotaPath | ForEach-Object {
Switch -Regex ($_) {
'^\s*$' {Break}
'^Quota Path:\s*(?<QuotaPath>.*?)\s*$' {$out = [ordered]@{ComputerName = $Server; QuotaPath = $Matches['QuotaPath']}; Break}
'^Description:\s*(?<Description>.*?)\s*$' {$out['Description'] = $Matches['Description']; Break}
'^Share Path:\s*(?<SharePath>.*?)\s*$' {$out['SharePath'] = $Matches['SharePath']; Break}
'^Source Template:\s*(?<SourceTemplate>.*?)\s*$' {$out['SourceTemplate'] = $Matches['SourceTemplate']; Break}
'^Quota Status:\s*(?<QuotaStatus>.*?)\s*$' {$out['QuotaStatus'] = $Matches['QuotaStatus']; Break}
'^Limit:\s*(?<Limit>.*?)\s*\((?<LimitType>.*?)\)$' {$out['Limit'] = $Matches['Limit']; $out['LimitType'] = $Matches['LimitType']; Break}
'^Used:\s*(?<Used>.*?)\s*\((?<UsedPercent>.*?)%\)$' {$out['Used'] = $Matches['Used']; $out['UsedPercent'] = $Matches['UsedPercent']; Break}
'^Available:\s*(?<Available>.*?)\s*$' {$out['Available'] = $Matches['Available']; Break}
'^Peak Usage:\s*(?<PeakUsage>.*?)\s*\((?<PeakUsageDate>.*?)\)$' {
$out['PeakUsage'] = $Matches['PeakUsage'];
$out['PeakUsageDate'] = [DateTime]::Parse($Matches['PeakUsageDate'], $dtProvider)
Break
}
'^Thresholds:\s*$' {Break}
'^\s+Warning\s+\(\s*(?<WarningThreshold>\d+)%\):\s*(?<WarningAction>.*?)\s*$'{
$out['WarningThreshold'] = $Matches['WarningThreshold']
$out['WarningAction'] = $Matches['WarningAction']
Break
}
'^\s+Limit\s+\(\s*(?<LimitThreshold>\d+)%\):\s*(?<LimitAction>.*?)\s*$'{
$out['LimitThreshold'] = $Matches['LimitThreshold']
$out['LimitAction'] = $Matches['LimitAction']
[PSCustomObject]$out
$out = $null
Break
}
default {
Write-Warning "Unexpected line: $($_)"
}
}
} | Export-Csv -NotypeInformation -Path $CsvPath
ASKER
Thanks 0BdA, that looks really great!
The only slight issue is it only picks the first SharePath and gives a warning for any subsequent ones and drops them, as the line doesn't start with SharePath, but has empty space
If there is an easy way to just account for that, either in new columns, or joined with ";" in the same column that would be great. But if it can't be easily done that's fine, it does the 99% of the data quickly, and if I have to manually pick through share paths, that's not the end of the world, just would be a nice to have.
Oh, and I needed to add "..." to the path to get the quotas recursively, but that is just a dirquota thing. "D:\..." . Or I could just drop /path:$DirquotaPath and then it will return all quotas on the servers, not just the one for a specific drive.
The only slight issue is it only picks the first SharePath and gives a warning for any subsequent ones and drops them, as the line doesn't start with SharePath, but has empty space
Quota Path: D:\parent\folder1
Description: None
Share Path: \\server\share\folder1
\\domain\dfsroot1\folder1
\\domain\dfsroot2\folder1
Source Template: 1 TB Limit Reports to User (Matches template)
...
If there is an easy way to just account for that, either in new columns, or joined with ";" in the same column that would be great. But if it can't be easily done that's fine, it does the 99% of the data quickly, and if I have to manually pick through share paths, that's not the end of the world, just would be a nice to have.
Oh, and I needed to add "..." to the path to get the quotas recursively, but that is just a dirquota thing. "D:\..." . Or I could just drop /path:$DirquotaPath and then it will return all quotas on the servers, not just the one for a specific drive.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Open in new window
dirquota is part of fsrm it is not installed on machines without this role