0

In the query below, I'd like to add the $srv value under the ServerName for each row.

[string]$srv = 'someserver'
gwmi -query "select * from Win32_LogicalDisk 
where DriveType = 2 OR DriveType = 3" -computername $srv | select ServerName, Name, FreeSpace,Size | export-csv -path .\$srv\BOX_LogicalDisk.csv -noType

I have tried adding $srv to the Select statement but no go.

Output should be like so:

ServerName  Name    FreeSpace   Size
Someserver  C:      82652930048 21340921856
Someserver  D:      7727915008  21340921856

Thanks!

A.G.
  • 2,089
  • 3
  • 30
  • 52

2 Answers2

0

Use a calculated property with Select-Object:

|select @{Name='ServerName';Expression={$srv}},Name,FreeSpace,Size
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
  • Nice, I have also found this: Get-WmiObject win32_logicaldisk -computername $srv | Where-Object { $_.DriveType -eq 3 -or $_.DriveType -eq 2 } | Select-Object SystemName,DeviceID,VolumeName,FreeSpace,Size | Export-Csv .\$svr\BOX_LogicalDisk.csv -NoTypeInformation – A.G. Nov 02 '15 at 22:53
0

Your command is returning all the data you need. Pipe it to format-list to see all properties like so:

gwmi -query "select * from Win32_LogicalDisk where DriveType = 2 OR DriveType = 3" -computername $srv | Format-List *

You'll see a PSComputerName property. So, just select it:

gwmi -query "select * from Win32_LogicalDisk where DriveType = 2 OR DriveType = 3" -computername $srv | select PSComputerName,Name,FreeSpace,Size
Robin
  • 1,602
  • 3
  • 16
  • 24