Friday, April 24, 2009

Exporting Physical Drive letters via PowerShell

I am diving back into PowerShell today. I need to see if i can figure out a way to feed a list of Server names and IP addresses to PowerShell and have it export to CSV all of the available drive letters for the system. If anyone can assist, it would be greatly appreciated.

Thanks much

6 comments:

EBGreen said...

So you have a list of servers and for each one you would want a row in n a CSV of the drive letters available on that server? A la:

Server1, E;J;M;Z
192.34.56.78, F;H;X;y

Aaron Perrault said...

@EBGreen, yup. That is exactly what i am looking for. Playing with get-content to read the file and then get-WMIObject Win32_LogicalDisk

EBGreen said...

See if this works (or at least points you in the right direction):

$result = @()
foreach($server in (Get-Content C:\temp\test.txt))
{
$temp = New-Object PsCustomObject
$drives = Get-WMIObject -Computer $server -Class Win32_LogicalDisk | Select-Object -ExpandProperty DeviceID
Add-Member -InputObject $temp -MemberType NoteProperty -Name Server -value $server
Add-Member -InputObject $temp -MemberType NoteProperty -Name Drives -value ([string]::Join(';', $drives))
$result += $temp
}

$result | Export-Csv C:\temp\test.csv

EBGreen said...

uggg...watchout for the extra line breaks that the blog formatting put in there.

EBGreen said...

Go here to get it without breaks:

http://poshcode.org/1058

Aaron Perrault said...

he shoots and he SCORES!!!

Thanks for that, this is exactly what i was looking for!

app