Just to start off, I am a novice. There is another post here about getting drive info:
powershellcommunity.org/Forums/tabid/54/forumid/14/postid/2432/view/topic/Default.aspx
I didn't want to monkey up that post with the discussion of my solution, but thought the two were closely related. The main difference is my problem was not only monitoring the drive space of servers but also to see trends. First lets see the code:
#------------------------------------------------------------------------------
# Title: drive_log.ps1
# Author: Jason Stephens
# Date: 27 Oct 08
# Description: Log drive space and free space of all drives
# Version: 1.0
#------------------------------------------------------------------------------
$computer = "AAMCMLM1"
$logLocation = "I:\Jason Stephens\AAMCMLM1\drive_log.xls"
# Start Microsoft Excel and open Excel document
$objExcel = New-Object -comobject Excel.Application
$objWorkbook = $objExcel.Workbooks.Open($logLocation)
# Select the next available cell in column A
$xlup = -4162
$range = "A" + $objExcel.Rows.Count
[void]$objExcel.Range($range).End($xlup).Activate()
[void]$objExcel.ActiveCell.Offset(1,0).Activate()
# Obtain drive information
$logicalDisks=Get-WMIObject -computername $computer -Class Win32_LogicalDisk -filter "DriveType=3"
# Insert information into excel log
$objExcel.ActiveCell.Value2 = Get-Date -Format g
[void]$objExcel.ActiveCell.Offset(0,1).Activate()
Foreach($disk in $logicaldisks)
{
 $size = "{0:N3}" -f ($disk.size/1GB)
 $free = "{0:N3}" -f ($disk.freespace/1GB)
 $objExcel.ActiveCell.Value2 = "$size / $free"
 [void]$objExcel.ActiveCell.Offset(0,1).Activate()
}
# Save and shut down excel
$objWorkbook.Save()
$objExcel.Quit()
[void][System.Runtime.Interopservices.Marshal]::ReleaseComObject($objExcel)
Remove-Variable objExcel
Now, as you can tell, I have used Microsoft's Excel instead of a CSV file. I am not sure of the wisdom of that other than it is only done for formatting reasons like a frozen header row.
Also, I didn't use the -Query that was used in the other post. Should I have? I don't have the drive name or title in my query because it is in the frozen frame in the excel document. I would ofcourse have to edit that should the drives change their setup. That doesn't happen that often, so not a major concern of mine.
I also didn't use a list of servers file. Mainly because of what the poster on the other post had a fear of. When one server failed, your script wouldn't finish correctly. It might not just be ping info but some other issue. That is why I have housed each script in the same folder as the excel log document and just scheduled a task to run a main powershell script that fires off each of the individual server scripts. I did this so I wouldn't have a bunch of scheduled jobs. Just the one to fire off the rest.
I was wondering if you guys wouldn't mind critiquing my little script for proper format, best practices, readability, best and most appropriate solutions, and just plain good ol' usability.
Just to clarify, this is the way I have it set up. I have a scheduled job fire off a script that has nothing in it but the commands to fire off these individual scripts. Each script gets drive info and records it in its excel log each day.
I thought of housing this all in one script. One idea I had was to have one script and just pull the servername from the arguments when I call the script over and over from the master script I have fire off from the schedule. What do you guys think?