There's a few issues here
- You are calling Format-Table prior to using the content elsewhere, Format-Table returns an output of format objects
- You are Piping your Write-Output to Select-Object, which is generally not how you want to got about this...
I suggest you follow the best practice of Filter Left, Format Right
When you pass objects through the pipe to another function, that function attempts to interpret those objects' properties as arguments. If you examine Format-Table output, it no-longer has the NumberOfCores property. That property was a member of the Win32_processor object type.
You cannot pipe output from Write-Host, as it does not return anything to the pipeline
Ultimately the code that you would want is
$N_cores = Get-WmiObject –class Win32_processor | Select-Object -Property NumberOfCores
Format-Table $N_cores |Write-Host
It should also be mentioned that if you intend to do anything with this script besides print to the console, you should not use Format-Table or Write-Host, instead use
`Write-Output $N_cores
as your second line. This will write the result not only to the console, but also pass the objects in the $N_cores variable to the pipeline
Write-Host vs Write-Output