September 22nd, 2009 by Michael
I have written a lot of scripts that use .txt files to read or store data, but I have a need to read some information from an .xml file. This could be done by treating the file as a simple txt file, but it would require some pretty good filtering that is already a part of the xml file. A quick search helped me locate this article:
http://blogs.msdn.com/kalleb/archive/2008/07/19/using-powershell-to-read-xml-files.aspx
Which contained the key to helping me with what I needed to do. The specific piece I needed was in Lesson 2:
Lesson 2:
Read data from an XML-file.
The XML-file that I’m going to read from has the following structure:
<Users>
<User>
<Name>Kalle</Name>
</User>
<User>
<Name>Becker</Name>
</User>
</Users>
Reading data from an XML-file is really easy in PowerShell! Use this command to load the file into an variable:
PS C:\Tmp> [xml]$userfile = Get-Content Accounts.xml
When the xml-file is loaded you can type “$userfile.U” and press tab to get auto completion!! It’s a breeze.
The trick is that you have to actually READ what is in front of you. The key here is to let PowerShell know that you are reading an xml file, and that is done by placing [xml] prior to getting the content. I missed that the first six times I read this and couldn’t figure out why I wasn’t getting the results I expected.
September 4th, 2009 by Michael
One of the things that we spend a lot of time on is trying to keep track of what servers have enough free space. We have a lot of different tools to check drive space, and we even use some of them from time to time. We have a pretty complicated system created by Rickey that creates a nice webpage, with highlighting for problem areas (percentage change from day to day, current percent free, etc.) It even puts the info into a database for historical reporting.
We don’t store or report on VMs currently, mainly because we were trying to keep track of total REAL disk used. VMs often don’t use as much as they think they do, so that would skew the results, as well as the fact that we are reporting on the hosts.
All of that is the reason that Patrick asked me to come up with some other tool to use for the VMs so I happened to find a few pieces of PowerShell script that I managed to put together to do a pretty good job of providing some of the info we wanted, and I thought I would share that with the 2 people who read my blog.
$servers = Get-Content servers.txt
#Open Excel and create a new workbook and worksheet
$ExcelSheet=New-Object -comobject Excel.application
$WorkBook=$ExcelSheet.WorkBooks.add(1)
$WorkSheet=$WorkBook.WorkSheets.item(1)
#Header row
$WorkSheet.cells.item(1,1)=”Computer Name”
$WorkSheet.cells.item(1,2)=”Disk Device ID”
$WorkSheet.cells.item(1,3)=”Volume Name”
$WorkSheet.cells.item(1,4)=”Size (GB)”
$WorkSheet.cells.item(1,5)=”Free Space (GB)”
$WorkSheet.cells.item(1,6)=”Space Used (GB)”
$WorkSheet.cells.item(1,7)=”Percent Used”
$i=2
ForEach ($ComputerName in $servers)
{
echo "Server Name : ", $ComputerName
$Disks = gwmi –computername $ComputerName win32_logicaldisk -filter "drivetype=3"
foreach ($Disk in $Disks)
{
$Size = "{0:0.0}" -f ($Disk.Size/1GB)
$FreeSpace = "{0:0.0}" -f ($Disk.FreeSpace/1GB)
$Used = ([int64]$Disk.size – [int64]$Disk.freespace)
$SpaceUsed = "{0:0.0}" -f ($Used/1GB)
$Percent = ($Used * 100.0)/$Disk.Size
$Percent = "{0:N0}" -f $Percent
$WorkSheet.cells.item($i,1)=$ComputerName
$WorkSheet.cells.item($i,2)=$Disk.deviceid
$WorkSheet.cells.item($i,3)=$Disk.volumename
$WorkSheet.cells.item($i,4)=$Size
$WorkSheet.cells.item($i,5)=$FreeSpace
$WorkSheet.cells.item($i,6)=$SpaceUsed
$WorkSheet.cells.item($i,7)=$Percent
$i=$i+1
}
}
#Show the results
$ExcelSheet.visible=$true
September 4th, 2009 by Michael
Patrick sent me this and I thought it was interesting:
At Backblaze, we provide unlimited storage to our customers for only $5 per month, so we had to figure out how to store hundreds of petabytes of customer data in a reliable, scalable way—and keep our costs low. After looking at several overpriced commercial solutions, we decided to build our own custom Backblaze Storage Pods: 67 terabyte 4U servers for $7,867.
In this post, we’ll share how to make one of these storage pods, and you’re welcome to use this design. Our hope is that by sharing, others can benefit and, ultimately, refine this concept and send improvements back to us. Evolving and lowering costs is critical to our continuing success at Backblaze.
Petabytes on a budget: How to build cheap cloud storage | Backblaze Blog