Ran Turner's answer provides the crucial pointer, but can be improved in two ways:
The CIM cmdlets (e.g., Get-CimInstance) superseded the WMI cmdlets (e.g., Get-WmiObject) in PowerShell v3 (released in September 2012). Therefore, the WMI cmdlets should be avoided, not least because PowerShell (Core) (v6+), where all future effort will go, doesn't even have them anymore. Note that WMI still underlies the CIM cmdlets, however. For more information, see this answer.
Format-Table, as all Format-* cmdlets, is designed to produce for-display formatting, for the human observer, and not to output data suitable for later programmatic processing (see this answer for more information).
- To instead create objects with a subset of the input objects' properties, use the
Select-Object cmdlet. (If the output object(s) have 4 or fewer properties and aren't captured, they implicitly format as if Format-Table had been called; with 5 or more properties, it is implicit Format-List).
Therefore:
# Creates a [pscustomobject] instance with
# .NumberOfCores and .NumberOfLogicalProcessors properties.
$cpuInfo =
Get-CimInstance –ClassName Win32_Processor |
Select-Object -Property NumberOfCores, NumberOfLogicalProcessors
# Save the values of interest in distinct variables, using a multi-assignment.
# Of course, you can also use the property values directly.
$cpuPhysicalCount, $cpuLogicalCount = $cpuInfo.NumberOfCores, $cpuInfo.NumberOfLogicalProcessors
Of course, if you're only interested in the values (CPU counts as mere numbers), you don't need the intermediate object and can omit the Select-Object call above.
As for a one-liner:
If you want a one-liner that creates distinct variables, without repeating the - costly - Get-CimInstance call, you can use an aux. variable that takes advantage of PowerShell's ability to use assignments as expressions:
$cpuPhysicalCount, $cpuLogicalCount = ($cpuInfo = Get-CimInstance -ClassName Win32_Processor).NumberOfCores, $cpuInfo.NumberOfLogicalProcessors
To save the numbers in distinct variables and output them (return them as a 2-element array), enclose the entire statement in (...).
To only output the numbers, simply omit the $cpuPhysicalCount, $cpuLogicalCount = part.