Posts

Showing posts from February, 2013

Historical Home Directory Usage

One of the issues we have to monitoring disk usage on our home directories. I needed a way to monitor who was using the most space, and to find out quickly who had used the most space most recently.

So to start out i have created a simple powershell script to get the entire home directory size, and put that information into a SQL database.

First i get a listing of all folders in the folder containing the home directories
then for each Folder, i get the total size, and send that info to SQL

Tables are setup [Name],[MB_Used],[Date]  , the date field is auto popluated

dir D:\homeDirs | ForEach-Object {
$colItems = (Get-ChildItem Z:\HOME\$_ -recurse | Measure-Object -property length -sum)
$DasName = $_
$DasSize = "{0:N2}" -f ($colItems.sum / 1MB)
$SQLServer = "SQLSERVER"
$SQLDBName = "DATABASE"
$SqlQuery = "insert into dbo.TABLENAME ([Name],[MB_Used]) Values ('$DasName','$DasSize')"
$SqlConnection = New-Object System.Data.SqlClient.S…