Trying to query a group of servers to get used disk space. I have total and free space easily accessed but used is hard to come by. I found the below powershell that works locally can someone help a powershell noob get this to work against a list of servers maybe in a text file and dump the data into excel?<\/p>\n
Get-WmiObject Win32_Volume -Filter \"DriveType='3'\" | ForEach {\n New-Object PSObject -Property @{\n Name = $_.Name\n Label = $_.Label\n FreeSpace_GB = ([Math]::Round($_.FreeSpace /1GB,2))\n TotalSize_GB = ([Math]::Round($_.Capacity /1GB,2))\n UsedSpace_GB = ([Math]::Round($_.Capacity /1GB,2)) - ([Math]::Round($_.FreeSpace /1GB,2))\n }\n }\n<\/code><\/pre>","upvoteCount":6,"answerCount":7,"datePublished":"2016-04-08T13:33:57.000Z","author":{"@type":"Person","name":"brandonhill0433","url":"https://community.spiceworks.com/u/brandonhill0433"},"acceptedAnswer":{"@type":"Answer","text":"
Something along these lines?<\/p>\n
$Computers = Get-Content C:\\blah.txt\n$Output = @()\n\nForeach ($Computer in $Computers)\n {\n $Output += Get-WmiObject Win32_Volume -Filter \"DriveType='3'\" -ComputerName $Computer | ForEach {\n New-Object PSObject -Property @{\n Name = $_.Name\n Label = $_.Label\n Computer = $Computer\n FreeSpace_GB = ([Math]::Round($_.FreeSpace /1GB,2))\n TotalSize_GB = ([Math]::Round($_.Capacity /1GB,2))\n UsedSpace_GB = ([Math]::Round($_.Capacity /1GB,2)) - ([Math]::Round($_.FreeSpace /1GB,2))\n }\n }\n }\n\n$Output | Export-Csv -NoTypeInformation -Path C:\\Space.csv\n<\/code><\/pre>\n
Edit: Sorry missed the Excel requirement initially.<\/p>","upvoteCount":3,"datePublished":"2016-04-08T13:44:55.000Z","url":"https://community.spiceworks.com/t/query-used-disk-space-using-powershell/487280/2","author":{"@type":"Person","name":"davelewis56","url":"https://community.spiceworks.com/u/davelewis56"}},"suggestedAnswer":[{"@type":"Answer","text":"
Trying to query a group of servers to get used disk space. I have total and free space easily accessed but used is hard to come by. I found the below powershell that works locally can someone help a powershell noob get this to work against a list of servers maybe in a text file and dump the data into excel?<\/p>\n
Get-WmiObject Win32_Volume -Filter \"DriveType='3'\" | ForEach {\n New-Object PSObject -Property @{\n Name = $_.Name\n Label = $_.Label\n FreeSpace_GB = ([Math]::Round($_.FreeSpace /1GB,2))\n TotalSize_GB = ([Math]::Round($_.Capacity /1GB,2))\n UsedSpace_GB = ([Math]::Round($_.Capacity /1GB,2)) - ([Math]::Round($_.FreeSpace /1GB,2))\n }\n }\n<\/code><\/pre>","upvoteCount":6,"datePublished":"2016-04-08T13:33:58.000Z","url":"https://community.spiceworks.com/t/query-used-disk-space-using-powershell/487280/1","author":{"@type":"Person","name":"brandonhill0433","url":"https://community.spiceworks.com/u/brandonhill0433"}},{"@type":"Answer","text":"Something like this should do what you want.<\/p>\n
Get-WmiObject Win32_Volume -Filter \"DriveType='3'\" -ComputerName ( Get-Content C:\\Computers.txt ) |\n ForEach-Object {\n [pscustomobject]@{\n Server = $_.SystemName\n Name = $_.Name\n Label = $_.Label\n FreeSpace_GB = ([Math]::Round($_.FreeSpace /1GB,2))\n TotalSize_GB = ([Math]::Round($_.Capacity /1GB,2))\n UsedSpace_GB = ([Math]::Round($_.Capacity /1GB,2)) - ([Math]::Round($_.FreeSpace /1GB,2))\n }\n } |\n Export-Csv -Path C:\\Output.csv -NoTypeInformation\n<\/code><\/pre>","upvoteCount":3,"datePublished":"2016-04-08T13:51:21.000Z","url":"https://community.spiceworks.com/t/query-used-disk-space-using-powershell/487280/3","author":{"@type":"Person","name":"gungnir","url":"https://community.spiceworks.com/u/gungnir"}},{"@type":"Answer","text":"Wow fast responses. Thanks for the help I’ll give this a try when a get a chance and report back.<\/p>","upvoteCount":0,"datePublished":"2016-04-08T13:55:14.000Z","url":"https://community.spiceworks.com/t/query-used-disk-space-using-powershell/487280/4","author":{"@type":"Person","name":"brandonhill0433","url":"https://community.spiceworks.com/u/brandonhill0433"}},{"@type":"Answer","text":"
Get-wmiobject will accept a list of computers. Read all your computer into a variable and use it like so. I read my servers out of AD but could easily be changed to read out of a file.<\/p>\n
$OUs = \"Domain Controllers\", \"Servers\"\nForEach ($ou in $OUs) {\n $Computers += Get-ADComputer -Filter * -SearchBase \"OU=$ou,dc=domain,dc=loc\" | select-object -expandproperty dnshostname\n}\nGet-WmiObject Win32_LogicalDisk -ComputerName $Computers -Filter \"DriveType='3'\" -ErrorAction SilentlyContinue | ...\n<\/code><\/pre>","upvoteCount":2,"datePublished":"2016-04-08T17:25:12.000Z","url":"https://community.spiceworks.com/t/query-used-disk-space-using-powershell/487280/5","author":{"@type":"Person","name":"davidgpaul","url":"https://community.spiceworks.com/u/davidgpaul"}},{"@type":"Answer","text":"\n\n
<\/div>\n
An Evil Penguin:<\/div>\n
\nSomething along these lines?<\/p>\n
$Computers = Get-Content C:\\blah.txt\n$Output = @()\n\nForeach ($Computer in $Computers)\n {\n $Output += Get-WmiObject Win32_Volume -Filter \"DriveType='3'\" -ComputerName $Computer | ForEach {\n New-Object PSObject -Property @{\n Name = $_.Name\n Label = $_.Label\n Computer = $Computer\n FreeSpace_GB = ([Math]::Round($_.FreeSpace /1GB,2))\n TotalSize_GB = ([Math]::Round($_.Capacity /1GB,2))\n UsedSpace_GB = ([Math]::Round($_.Capacity /1GB,2)) - ([Math]::Round($_.FreeSpace /1GB,2))\n }\n }\n }\n\n$Output | Export-Csv -NoTypeInformation -Path C:\\Space.csv\n<\/code><\/pre>\nEdit: Sorry missed the Excel requirement initially.<\/p>\n<\/blockquote>\n<\/aside>\n
Thanks for the help this worked like a charm.<\/p>","upvoteCount":1,"datePublished":"2016-04-11T10:59:40.000Z","url":"https://community.spiceworks.com/t/query-used-disk-space-using-powershell/487280/6","author":{"@type":"Person","name":"brandonhill0433","url":"https://community.spiceworks.com/u/brandonhill0433"}},{"@type":"Answer","text":"
how do I insert into sql table? \nthank you.<\/p>\n\n\n
<\/div>\n
CheesyBread:<\/div>\n
\nTrying to query a group of servers to get used disk space. I have total and free space easily accessed but used is hard to come by. I found the below powershell that works locally can someone help a powershell noob get this to work against a list of servers maybe in a text file and dump the data into excel?<\/p>\n
Get-WmiObject Win32_Volume -Filter \"DriveType='3'\" | ForEach {\n New-Object PSObject -Property @{\n Name = $_.Name\n Label = $_.Label\n FreeSpace_GB = ([Math]::Round($_.FreeSpace /1GB,2))\n TotalSize_GB = ([Math]::Round($_.Capacity /1GB,2))\n UsedSpace_GB = ([Math]::Round($_.Capacity /1GB,2)) - ([Math]::Round($_.FreeSpace /1GB,2))\n }\n }\n<\/code><\/pre>\n<\/blockquote>\n<\/aside>\n\n\n
<\/div>\n
CheesyBread:<\/div>\n
\nTrying to query a group of servers to get used disk space. I have total and free space easily accessed but used is hard to come by. I found the below powershell that works locally can someone help a powershell noob get this to work against a list of servers maybe in a text file and dump the data into excel?<\/p>\n
Get-WmiObject Win32_Volume -Filter \"DriveType='3'\" | ForEach {\n New-Object PSObject -Property @{\n Name = $_.Name\n Label = $_.Label\n FreeSpace_GB = ([Math]::Round($_.FreeSpace /1GB,2))\n TotalSize_GB = ([Math]::Round($_.Capacity /1GB,2))\n UsedSpace_GB = ([Math]::Round($_.Capacity /1GB,2)) - ([Math]::Round($_.FreeSpace /1GB,2))\n }\n }\n<\/code><\/pre>\n<\/blockquote>\n<\/aside>","upvoteCount":0,"datePublished":"2018-07-19T18:41:43.000Z","url":"https://community.spiceworks.com/t/query-used-disk-space-using-powershell/487280/7","author":{"@type":"Person","name":"marcospaiva","url":"https://community.spiceworks.com/u/marcospaiva"}}]}}
Trying to query a group of servers to get used disk space. I have total and free space easily accessed but used is hard to come by. I found the below powershell that works locally can someone help a powershell noob get this to work against a list of servers maybe in a text file and dump the data into excel?
Get-WmiObject Win32_Volume -Filter "DriveType='3'" | ForEach {
New-Object PSObject -Property @{
Name = $_.Name
Label = $_.Label
FreeSpace_GB = ([Math]::Round($_.FreeSpace /1GB,2))
TotalSize_GB = ([Math]::Round($_.Capacity /1GB,2))
UsedSpace_GB = ([Math]::Round($_.Capacity /1GB,2)) - ([Math]::Round($_.FreeSpace /1GB,2))
}
}
6 Spice ups
Something along these lines?
$Computers = Get-Content C:\blah.txt
$Output = @()
Foreach ($Computer in $Computers)
{
$Output += Get-WmiObject Win32_Volume -Filter "DriveType='3'" -ComputerName $Computer | ForEach {
New-Object PSObject -Property @{
Name = $_.Name
Label = $_.Label
Computer = $Computer
FreeSpace_GB = ([Math]::Round($_.FreeSpace /1GB,2))
TotalSize_GB = ([Math]::Round($_.Capacity /1GB,2))
UsedSpace_GB = ([Math]::Round($_.Capacity /1GB,2)) - ([Math]::Round($_.FreeSpace /1GB,2))
}
}
}
$Output | Export-Csv -NoTypeInformation -Path C:\Space.csv
Edit: Sorry missed the Excel requirement initially.
3 Spice ups
gungnir
(Gungnir)
April 8, 2016, 1:51pm
3
Something like this should do what you want.
Get-WmiObject Win32_Volume -Filter "DriveType='3'" -ComputerName ( Get-Content C:\Computers.txt ) |
ForEach-Object {
[pscustomobject]@{
Server = $_.SystemName
Name = $_.Name
Label = $_.Label
FreeSpace_GB = ([Math]::Round($_.FreeSpace /1GB,2))
TotalSize_GB = ([Math]::Round($_.Capacity /1GB,2))
UsedSpace_GB = ([Math]::Round($_.Capacity /1GB,2)) - ([Math]::Round($_.FreeSpace /1GB,2))
}
} |
Export-Csv -Path C:\Output.csv -NoTypeInformation
3 Spice ups
Wow fast responses. Thanks for the help I’ll give this a try when a get a chance and report back.
Get-wmiobject will accept a list of computers. Read all your computer into a variable and use it like so. I read my servers out of AD but could easily be changed to read out of a file.
$OUs = "Domain Controllers", "Servers"
ForEach ($ou in $OUs) {
$Computers += Get-ADComputer -Filter * -SearchBase "OU=$ou,dc=domain,dc=loc" | select-object -expandproperty dnshostname
}
Get-WmiObject Win32_LogicalDisk -ComputerName $Computers -Filter "DriveType='3'" -ErrorAction SilentlyContinue | ...
2 Spice ups
An Evil Penguin:
Something along these lines?
$Computers = Get-Content C:\blah.txt
$Output = @()
Foreach ($Computer in $Computers)
{
$Output += Get-WmiObject Win32_Volume -Filter "DriveType='3'" -ComputerName $Computer | ForEach {
New-Object PSObject -Property @{
Name = $_.Name
Label = $_.Label
Computer = $Computer
FreeSpace_GB = ([Math]::Round($_.FreeSpace /1GB,2))
TotalSize_GB = ([Math]::Round($_.Capacity /1GB,2))
UsedSpace_GB = ([Math]::Round($_.Capacity /1GB,2)) - ([Math]::Round($_.FreeSpace /1GB,2))
}
}
}
$Output | Export-Csv -NoTypeInformation -Path C:\Space.csv
Edit: Sorry missed the Excel requirement initially.
Thanks for the help this worked like a charm.
1 Spice up
how do I insert into sql table?
thank you.
CheesyBread:
Trying to query a group of servers to get used disk space. I have total and free space easily accessed but used is hard to come by. I found the below powershell that works locally can someone help a powershell noob get this to work against a list of servers maybe in a text file and dump the data into excel?
Get-WmiObject Win32_Volume -Filter "DriveType='3'" | ForEach {
New-Object PSObject -Property @{
Name = $_.Name
Label = $_.Label
FreeSpace_GB = ([Math]::Round($_.FreeSpace /1GB,2))
TotalSize_GB = ([Math]::Round($_.Capacity /1GB,2))
UsedSpace_GB = ([Math]::Round($_.Capacity /1GB,2)) - ([Math]::Round($_.FreeSpace /1GB,2))
}
}
CheesyBread:
Trying to query a group of servers to get used disk space. I have total and free space easily accessed but used is hard to come by. I found the below powershell that works locally can someone help a powershell noob get this to work against a list of servers maybe in a text file and dump the data into excel?
Get-WmiObject Win32_Volume -Filter "DriveType='3'" | ForEach {
New-Object PSObject -Property @{
Name = $_.Name
Label = $_.Label
FreeSpace_GB = ([Math]::Round($_.FreeSpace /1GB,2))
TotalSize_GB = ([Math]::Round($_.Capacity /1GB,2))
UsedSpace_GB = ([Math]::Round($_.Capacity /1GB,2)) - ([Math]::Round($_.FreeSpace /1GB,2))
}
}