VMware Cloud Community
tdubb123
Expert
Expert

how to export this to csv

any idea how to output this to a file ?

 

$servers = get-content "c:\scripts\servers.txt"

Foreach ($server in $servers) {

Get-WmiObject Win32_Volume -ComputerName $server| ForEach {
New-Object PSObject -Property @{
Computername = $server
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))
blocksize = $_.blocksize
filesystem = $_.filesystem
}
} ft -autosize | export-csv "test.csv"}

 

 

this only gives me the last server output not everything

0 Kudos
1 Reply
LucD
Leadership
Leadership

Try something like this

 

Get-WmiObject Win32_Volume -ComputerName $server | 
    ForEach-Object -Object -Process {
        New-Object PSObject -Property @{
            Computername = $server
            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))
            blocksize    = $_.blocksize
            filesystem   = $_.filesystem
        }
    } | Export-Csv -Path "test.csv"


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos