<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Swaziland Tech Safari &#187; powershell</title>
	<atom:link href="http://www.briandeyo.us/brd/wp/index.php/tag/powershell/feed" rel="self" type="application/rss+xml" />
	<link>http://www.briandeyo.us/brd/wp</link>
	<description>The internet is the best tool to save humanity.</description>
	<lastBuildDate>Sun, 20 Nov 2011 14:57:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Time to do work?</title>
		<link>http://www.briandeyo.us/brd/wp/index.php/2008/05/21/time-to-do-work</link>
		<comments>http://www.briandeyo.us/brd/wp/index.php/2008/05/21/time-to-do-work#comments</comments>
		<pubDate>Wed, 21 May 2008 22:03:49 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[Computers and Technology]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://www.theboobiehatch.com/tbh/blaarg/?p=11</guid>
		<description><![CDATA[When I was working at IBM there was a daily report that I issued on the state of the environment, drivespace, and crap like that.  I always told myself that if I ever had time I would automate much or all of the process as thoroughly as possible.  As time was not on my side… [...]]]></description>
			<content:encoded><![CDATA[<div class="entry">
<p>When I was working at IBM there was a daily report that I issued on the state of the environment, drivespace, and crap like that.  I always told myself that if I ever had time I would automate much or all of the process as thoroughly as possible.  As time was not on my side… that never happened, and instead I browsed my computer for 4 different servers, and 32 different directories every working day just so I knew how much drivespace I *didn’t* have left.</p>
<p>Now that I don’t work for those ingrates anymore it is much easier to breathe and script a bit.  Here’s what 2 hours netted me:</p>
<p style="padding-left: 30px;"># Returns pre-formatted list of drivespace available to all logical drives on given servers<br />
# outputs list to text file</p>
<p style="padding-left: 30px;">$output = “c:\scripting\mtptfs.txt”<br />
del $output<br />
$evs = @(”evs01″,”evs02″,”evs03″)</p>
<p style="padding-left: 30px;">foreach ($name in $evs) {<br />
gwmi -computer $name -class win32_volume -filter “drivetype=3″ |<br />
  sort-object Caption |<br />
    select-object SystemName, Caption,{[math]::round($_.Capacity /1GB, 2)},{[math]::round($_.freespace / 1GB, 2)} &gt;&gt; $output<br />
}</p>
<p>That is a neat little powershell script.  It grabs info from a WMI object of each of my exchange virtual servers, and dumps some numbers to a text file, in a not so classy way.</p>
<p>After another 2 hours I ditched all of that and came to a decent, but not completely done final product:</p>
<p style="padding-left: 30px;">###<br />
###  Returns pre-formatted list of drivespace available to all<br />
###  exchange virtual servers, and returns the information in a<br />
###  programmatically generated excel spreadsheet<br />
###<br />
�<br />
�<br />
�<br />
### CREATES NEW EXCEL FILE USING COM OBJECT<br />
$Excel = New-Object -Com Excel.Application<br />
$Excel.visible = $True<br />
$Excel = $Excel.Workbooks.Add()<br />
 </p>
<p style="padding-left: 30px;">###SETS VARIABLE FOR WORKSHEETS<br />
$p = 1<br />
 </p>
<p style="padding-left: 30px;">###CREATES ARRAY FOR WHICH SERVERS TO QUERY<br />
$evs = @(”EVS01″,”EVS02″,”EVS03″)<br />
�<br />
�<br />
�<br />
###LOOP FOR CREATING 1 EXCEL SHEET FOR EACH EVS<br />
foreach ($name in $evs) {<br />
 </p>
<p style="padding-left: 30px;">###WRITES COLUMN HEADERS ON EACH EXCEL SHEET<br />
$Sheet = $Excel.WorkSheets.Item($p)<br />
$Sheet.Cells.Item(1,1) = “Computer”<br />
$Sheet.Cells.Item(1,2) = “Drive/MountPoint”<br />
$Sheet.Cells.Item(1,3) = “TOTAL SIZE”<br />
$Sheet.Cells.Item(1,4) = “FREE SPACE”<br />
 </p>
<p style="padding-left: 30px;">###CHANGES COLORS AND FONTS ON COLUMN HEADERS<br />
$WorkBook = $Sheet.UsedRange<br />
$WorkBook.Interior.ColorIndex = 8<br />
$WorkBook.Font.ColorIndex = 11<br />
$WorkBook.Font.Bold = $True<br />
�<br />
�<br />
�<br />
###SETS CELL STARTING POINT FOR WRITING EVS &amp; DRIVESPACE INFORMATION<br />
$intRow = 2<br />
 </p>
<p style="padding-left: 30px;">###POWERSHELL SCRIPT FOR GETTING WMI INFORMATION ABOUT ALL LOGICAL VOLUMES ON AN EVS<br />
$colItems = gwmi -computer $name -class win32_volume -filter “drivetype=3″ | sort-object Caption<br />
 </p>
<p style="padding-left: 30px;">###LOOP FOR WRITING WMI INFORMATION BY ROW<br />
foreach ($objItem in $colItems) {<br />
    $Sheet.Cells.Item($intRow,1) = $objItem.SystemName<br />
    $Sheet.Cells.Item($intRow,2) = $objItem.Caption<br />
    $Sheet.Cells.Item($intRow,3) = $objItem.Capacity / 1GB<br />
    $Sheet.Cells.Item($intRow,4) = $objItem.freespace / 1GB<br />
    $intRow = $intRow + 1<br />
�<br />
}<br />
�<br />
###CHANGES WORKBOOK TO NEXT SHEET<br />
$p = $p + 1<br />
 </p>
<p style="padding-left: 30px;">###ADJUSTS COLUMN WIDTH FOR SHEET AUTOMATICALLY<br />
$WorkBook.EntireColumn.AutoFit()<br />
 </p>
<p style="padding-left: 30px;">###FORMATS THE CAPACITY INFORMATION INTO INTEGERS WITH TWO DECIMAL PLACES<br />
$Sheet.Cells.NumberFormat = “#.00″<br />
 </p>
<p style="padding-left: 30px;">}</p>
<p>This script is much nicer.  It creates a new excel file using the COM object, and dumps each EVS to its own sheet.  This comes complete with colors.  I have also included the pictures, circles, and arrows on the back of each one, and a paragraph describing what each one was.</p>
<p>I didn’t finish this completely because I ran out of time trying to get the borders completed.  whah.</p>
<p>All that being said my 2nd week with powershell is actually a good experience.  I haven’t been interested in scripting like this since <a href="http://www.bitchx.org/">BitchX</a> was my girlfriend.</div>
]]></content:encoded>
			<wfw:commentRss>http://www.briandeyo.us/brd/wp/index.php/2008/05/21/time-to-do-work/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

