Reputation: 31
I entered gwmi win32_product | select -property name | select -first 1
and output to a file. My result was @{name=Google Talk Plugin}
.
How can I get rid of @{}
, and name. I only want it to show Google Talk Plugin
?
Upvotes: 3
Views: 30158
Reputation: 35
I add some code as I found this question with google.
Frode F. solution is the best one.
If you write out something like:
Get-ADComputer -Filter * -SearchBase $OU | Select-Object Name
you get a proper List of all Computers in an OU. You can also pipe that to a CVS/HTML file and its still nice.
| Export-CSV "mylist.csv"
But if you store it into a variable (array) every name will be wrapped in @{}.
In my case I needed computer names in a variable. Here is the solution thanks to Frodo:
$computerList = Get-ADComputer -Filter * -SearchBase $OU | Select-Object -ExpandProperty Name
Hope it helps someone. (would add it as comment under the right solution, but I don't have enough reputation to do so)
Upvotes: 0
Reputation: 13
I ran into a problem similar with
$drive = Get-WmiObject Win32_LogicalDisk -ComputerName $servername | Select-Object DeviceID
$drive comes up as @{DeviceID=C:}, @{DeviceID=D:}, ...
Here is my brute force hack at it.
The second Trim statement was because for some reason if I put it in the first Trim it starts to Trim the letters in the Drive =D: becomes :
enter code here
$Asdrive = @() #declared before to get rid of null pointer issue, also to tell PS this is an array not a string
#Write-Host "Trimming for Get-WmiObject"
for($i=0;$i -lt $drive.length; $i++) {
[string]$sdrive = $drive[$i]
[string]$sdrive1 = $sdrive.Trim("@","{","}","D","e","v","i","c","e","I","D")
[string]$sdrive2 = $sdrive1.Trim("=")
$Asdrive += $sdrive2
}
Upvotes: 1
Reputation: 68331
If you're running at least Version 3, you can also use the member enumeration feature and then array slicing to take the first one, instead of using select:
(gwmi win32_product).name[0]
Upvotes: 0
Reputation: 54951
@{}
means your exporting an object with properties. Try the -ExpandProperty
parameter in Select-Object
. You could also combine both select-object
commands, like:
gwmi win32_product | select -expandproperty name -first 1
Upvotes: 14