Both examples do not work because of incorrect PowerShell syntax. The following code lists the volume sizes of the current host (using PowerShell 5.0):
Get-WmiObject win32_logicalDisk -filter "DriveType=3" | %{ $_.DeviceID; $_.FreeSpace/1GB }
The following code lists the volume sizes of hosts listed in server.txt:
Get-Content server.txt | %{ Get-WMIObject –computername $_ Win32_LogicalDisk -filter "DriveType=3" | %{ $_.DeviceID; $_.FreeSpace/1GB } }
Sidenote
Note that the outer place holder $_
enumerates the server addresses whereas the inner place holder $_
enumerates the devices. That's a frequent gotcha for PowerShell newbies. If you wanted to use the server address in the inner loop, you'd have to assign it to a new variable in the outer loop.
The forum software used here is flawed. In post previews, it displays $_
correctly as a $_
even if not escaped as code. But the final post removes the underscore, thus making the PowerShell examples incorrect.