Below is the code I have which is reproducible on your system as well :
$object=New-Object psobject
$computerName ='servername'
$Ostype = (Get-WmiObject -Class Win32_OperatingSystem -ComputerName $computerName -ErrorAction SilentlyContinue ).Caption
$PhysicalCores = Get-WmiObject -Class Win32_processor -ComputerName $computerName | Measure-Object -Property Numberofcores -Sum | select Sum
$LogicalCores = Get-WmiObject -Class Win32_processor -ComputerName $computerName | Measure-Object -Property NumberofLogicalProcessors -Sum | select Sum
$NumberofSockets=Get-WmiObject -Class win32_processor -ComputerName $computerName| Measure-Object -Property socketdesignation |select Count
$computerram=(Get-WMIObject -class Win32_PhysicalMemory -ComputerName $computerName |Measure-Object -Property capacity -Sum | % {[Math]::Round(($_.sum / 1GB),2)})
$type=get-wmiobject win32_computersystem -ComputerName $computerName |select model
$object=New-Object psobject
$object | Add-Member -MemberType NoteProperty -Name ComputerName -Value $computerrealname
$object | Add-Member -MemberType NoteProperty -Name ComputerType -Value $Computertype
$object | Add-Member -MemberType NoteProperty -Name OSType -Value $Ostype
$object | Add-Member -MemberType NoteProperty -Name TotalMemory_GB -Value $computerram
$object | Add-Member -MemberType NoteProperty -name NumberofProcessors -Value $PhysicalCores
$object | Add-Member -MemberType NoteProperty -name NumberofLogicalProcessors -Value $LogicalCores
$object | Add-Member -MemberType NoteProperty -name NumberofSockets -Value $NumberofSockets
$object | Add-Member -MemberType NoteProperty -name MachineType -Value $type
$object | Out-GridView
Output is like below
As you can see, output for some of the variables in showing in curly brackets, how to remove them?
Things I have tried
1. Without adding variables to object, output doesn't come in curly brackets
2. Tried doing an sum.toint32() but no luck
Can some one please shed light on what I am doing wrong?
Building a PSCustomObject there is no need to store the values in a variable first. From your code it is not clear where you get some vars from.
You just need to expand the one property you would like to include. For example:
The issue is that
$PhysicalCores
is some object with one or more key=value pairs, which are represented as@{key=value}
.You could also do this during assignment, for example:
or