Reputation: 193
I want to list the files of C: drive. First of all, I want to get the device ID from logical disk wmi object, and list it.
Below command returns:
Get-WmiObject -class Win32_logicaldisk
DeviceID : C:
DriveType : 3
ProviderName :
FreeSpace : 940371968
Size : 125809192960
VolumeName :
But this command:
Get-WmiObject -class Win32_logicaldisk | select deviceid | Get-ChildItem -path {$_}
gives below error:
Get-ChildItem : Cannot find drive. A drive with the name '@{deviceid=C' does not exist. At line:1 char:60
+ Get-WmiObject -class Win32_logicaldisk | select deviceid | Get-ChildItem -path { ...
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (@{deviceid=C:String) [Get-ChildItem], DriveNotFoundException
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
Get-ChildItem -path accepts pipeline input, how we can solve this ?
Upvotes: 1
Views: 561
Reputation: 1716
Your Select
is returning an Object with a property named DeviceID.
Use -ExpandProperty
to get the property value, then pipe that:
Get-WmiObject -class Win32_logicaldisk | select -expandproperty deviceid | Get-ChildItem -path {$_}
Upvotes: 3
Reputation: 621
You could also just select the property in the Object that gets returned. In this case, $_.DeviceID
Get-WmiObject -class Win32_logicaldisk | select deviceid | Get-ChildItem -path {$_.DeviceID}
Upvotes: 2