psobject results not as expected

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 7 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: psobject results not as expected

Post by jvierra »

OR ...
  1. $LogicalDisks = (Get-WmiObject Win32_Volume -Filter "DriveType='3'" | select -expand DriveLetter ) -join '|'
  2. $obj | Add-Member -membertype NoteProperty -Name DriveLetter -Value $LogicalDisks
User avatar
russ
Posts: 12
Last visit: Mon Sep 19, 2016 6:03 pm

Re: psobject results not as expected

Post by russ »

MikeFRobbins wrote:Where-Object in the first line of adding members in your script doesn't do anything. Changing it to ForEach-Object at least narrows it down to only the drive letter property:

Code: Select all

$obj | Add-Member -membertype NoteProperty -Name DriveLetter -Value (($LogicalDisks | ForEach-Object { $_.DriveLetter } ) | out-string).Trim()
Thank you your ForEach-Object suggestion did the trick!
This topic is 7 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked