Advertisement

05.21.2008 at 06:03AM PDT, ID: 23420605
[x]
Attachment Details

Syntax Assistance Please

Asked by kjanicke in MSH/Monad PowerShell, Scripting Languages

Tags: PowerShell

I'm doing something screwy.  This script runs thru a bunch of folders and checks the size, and it works (sort of) but I'm setting up the hash wrong.  It seems to reset for each folder it goes thru.  So the final output only shows space hogs in folderpathfour.

Yes, I am program develeopment challenged.  Is there a knowledge level before "Beginner?"

Eventually I want to put a little bit in here also to check the drive size of a specific drive on a file server.  five drives configured but I only want to check the space available on F drive.

This is my snipette for checking drive sizes (not the complete script).

$DCservers = @("serverone", "servertwo", "serverthree")
$body = @()
$recent = get-date
foreach ($server in $DCservers) {
$header = "----" + $server.ToUpper() + "----"
$driveinfo = Get-WmiObject -ComputerName $server win32_logicaldisk -filter DriveType=3 | format-table @{Label="Drive";Expression={$_.DeviceID}}, VolumeName, @{ Label = "Total Space"; Expression = {"{0,7:n2} GB" -f ($_.Size/1GB)}}, @{ Label = "Free Space"; Expression = {"{0,7:n2} GB" -f ($_.FreeSpace/1GB)}}, @{Label="Status";Expression={if($_.FreeSpace -lt ($_.Size*.3)) {"{0:n1}%  FREE" -f ((($_.freespace/1gb)/($_.size/1gb)*100))} else {"Acceptable"}}}
$Body += $header
$Body += $driveinfo
$Body += "`n"
}Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
[System.Net.Mail.MailMessage]$message = new-object System.Net.Mail.MailMessage
[System.Net.Mail.SmtpClient]$smtpClient = new-object System.Net.Mail.smtpclient("server.com")
$message.to.Add("emailaddressone")
$message.to.Add("emailaddresstwo")
$message.From = "emailaddressfrom"
$message.Subject = "User Home Drives over 5 GB"
$body =@()
$UserFolders = @(
	"\\server\folderpathone", `
	"\\server\folderpathtwo", `
	"\\server\folderpaththree", `
	"\\server\folderpathfour")
foreach ($startFolder in $UserFolders) {
  $SpaceHogs = New-Object System.Collections.HashTable
  $colItems = (Get-ChildItem $startFolder | Where-Object {$_.PSIsContainer -eq $True})
  foreach ($i in $colItems)
    {
        $subFolderItems = (Get-ChildItem $i.FullName -recurse | Measure-Object -property length -sum ) 
	If($subFolderItems.sum -gt 5GB)
	{
	$SpaceHogs[$i.name] = "{0:N2}" -f ($subFolderItems.sum / 1GB) + " GB"
	#$SpaceHogs = ($i.Name + " -- " + "{0:N2}" -f ($subFolderItems.sum / 1GB) + " GB")
	}
	else {}
    }
}
$message.body = $SpaceHogs.GetEnumerator() | Sort-Object value -Descending | Out-String
$smtpclient.send($message)
 
Keywords: Syntax Assistance Please
 
Loading Advertisement...
 
[+][-]05.22.2008 at 04:38AM PDT, ID: 21622809

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]05.22.2008 at 05:48AM PDT, ID: 21623259

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]05.22.2008 at 07:50AM PDT, ID: 21624288

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.22.2008 at 08:12AM PDT, ID: 21624527

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.22.2008 at 08:22AM PDT, ID: 21624626

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.22.2008 at 08:56AM PDT, ID: 21624995

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.22.2008 at 09:19AM PDT, ID: 21625220

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.22.2008 at 09:20AM PDT, ID: 21625231

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MSH/Monad PowerShell, Scripting Languages
Tags: PowerShell
Sign Up Now!
Solution Provided By: ramrom
Participating Experts: 4
Solution Grade: A
 
 
[+][-]05.22.2008 at 02:30PM PDT, ID: 21627830

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.22.2008 at 02:31PM PDT, ID: 21627834

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628