Am trying to do a few things in one script.
Would like to list out servers that:
1- match a specific OS
2- have 20GB-50GB free
I am able to list out servers and their OS,
am able to list drive info and format how I want...
but not able to figure how to only report on specific size from the drive space results
Also not able to combine these items.
am learning, but have been banging my head on this for a while now.
You'll have to query that information from the servers using two calls.
# populate $computers with a collection of computer name strings# e.g., $computers = @('SERVER1','SERVER2','SERVER3')# offline computers will be skipped with an error message by default
foreach ($computer in $computers) { $drive = get-wmiobject -class win32_logicaldisk -filter "deviceid='c:'" -computername $computer $os = get-wmiobject -class win32_operatingsystem -computername $computer if ($drive.freespace -lt 50GB -and $drive.freespace -gt 20GB -and $os.version -eq 'whatever') { $props = @{'ComputerName'=$computer;'OSVersion'=$os.version;'FreeSpace'=$drive.freespace} new-object -typename psobject -prop $props }}
Something like that, I imagine. My book, Learn Windows PowerShell in a Month of Lunches, has specific examples around combining pieces of information like this. Something you might look into, if you're interested. My example here isn't the most elegant approach, but it's probably the shortest.