0

I'm a super-noob when it comes to powershell. I've been able to extract the WMIobject win32_LogicalDisk info except for the ADComputer identity info. See my code and columns needed to populate. I keep getting a blank under user. Any thoughts?

$exportPath = "\\Server01\users\ohyeah\Downloads\testfolder"

$computers = Get-Content "\\Server01\users\ohyeah\Downloads\testfolder\computers.txt"

$driveinfo = Get-WMIobject win32_LogicalDisk -ComputerName $computers -filter "DriveType=3" | Select-Object SystemName, DeviceID, VolumeName,
@{Name="Size_GB"; Expression={"{0:N1}" -f($_.size/1gb)}},
@{Name="FreeSpace_GB"; Expression={"{0:N1}" -f($_.freespace/1gb)}},
@{Name="%_FreeSpace_GB"; Expression={"{0:N2}%" -f(($_.freespace/$_.size)*100)}},
@{Name="User"; Expression={$(Get-ADComputer -identity $_ -Properties Description | ft -a Description)}},
@{Name="Date"; Expression={$(Get-Date -format 'g')}} 

$driveinfo | Out-GridView 
$driveinfo | Format-Table -AutoSize
$driveinfo | Export-Csv "$exportPath\test.csv" -NoTypeInformation -NoClobber -Append

SystemName DeviceID VolumeName Size_GB FreeSpace_GB %_FreeSpace_GB User Date

2
  • are you referring to the User calculated property? does the expression part of that line run correctly when you run it alone in your loop?
    – Lee_Dailey
    Dec 7, 2018 at 19:47
  • The Get-WMIObject sends on an object that contains the property PSComputer if I remember right. Try -identity $_.PSComputer and see if that helps. Dec 7, 2018 at 20:34

1 Answer 1

0

You already have the computer name, via the SystemName property. Just pass that in directly.

You also cannot use that Format-Table in that calculated property that way, especially if all you are asking for is a single field property which is nothing but a note field.

Lastly, unless that description field is populated, it will be empty, also using that Description property is not part of the default list, you have to ask for it asking for all properties and then specific property.

Running this on a local domain joined host...

# This will give you the data in the Description property
Clear-Host

$computers = $env:COMPUTERNAME

$driveinfo = Get-WMIobject win32_LogicalDisk -ComputerName $computers -filter "DriveType=3" | 
Select-Object SystemName, DeviceID, VolumeName,
@{Name="Size_GB"; Expression={"{0:N1}" -f($_.size/1gb)}},
@{Name="FreeSpace_GB"; Expression={"{0:N1}" -f($_.freespace/1gb)}},
@{Name="%_FreeSpace_GB"; Expression={"{0:N2}%" -f(($_.freespace/$_.size)*100)}},
@{Name="User"; Expression={$(Get-ADComputer -identity $_.SystemName -Properties *).Description}},
@{Name="Date"; Expression={$(Get-Date -format 'g')}} 

$driveinfo | Out-GridView


# This will give you the full DN of the computer object
Clear-Host

$computers = $env:COMPUTERNAME

$driveinfo = Get-WMIobject win32_LogicalDisk -ComputerName $computers -filter "DriveType=3" | 
Select-Object SystemName, DeviceID, VolumeName,
@{Name="Size_GB"; Expression={"{0:N1}" -f($_.size/1gb)}},
@{Name="FreeSpace_GB"; Expression={"{0:N1}" -f($_.freespace/1gb)}},
@{Name="%_FreeSpace_GB"; Expression={"{0:N2}%" -f(($_.freespace/$_.size)*100)}},
@{Name="User"; Expression={$(Get-ADComputer -identity $_.SystemName -Properties Description)}},
@{Name="Date"; Expression={$(Get-Date -format 'g')}} 

$driveinfo | Out-GridView

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.