Get-CPUCoreCount.ps1


<#PSScriptInfo
 
.VERSION 1.0.0.0
 
.GUID c90a4be1-0f4f-4329-b3e2-0c48932c5ebf
 
.AUTHOR Jeffrey Snover
 
.COMPANYNAME Microsoft
 
.COPYRIGHT
 
.TAGS
 
.LICENSEURI
 
.PROJECTURI
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
 
 
#>


<#
 
.DESCRIPTION
 Get the CPU Core count
 
#>
 
[CmdletBinding()]
param(
    [Parameter(Mandatory=$true, ValueFromPipeline=$true)]
    [CimSession[]]
    ${CimSession},

    [Parameter(ValueFromPipelineByPropertyName=$true)]
    [Alias('CN','ServerName')]
    [string[]]
    ${ComputerName},

    [Alias('OT')]
    [uint32]
    ${OperationTimeoutSec})

begin
{
    try {
        $outBuffer = $null
        if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer))
        {
            $PSBoundParameters['OutBuffer'] = 1
        }
        $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('CimCmdlets\Get-CimInstance', [System.Management.Automation.CommandTypes]::Cmdlet)
        $scriptCmd = {
            & $wrappedCmd -classname win32_processor -Namespace root/cimv2 -Property Name,NumberOfCores,NumberOfEnabledCore,NumberOfLogicalProcessors @PSBoundParameters |
            Select-Object  -property `
                    @{Name="ComputerName";Expression = {$Name = $_.PSComputerName; if ($Name){$name}else{hostname}}},
                    @{Name="Cores"       ;Expression = {$_.NumberOfCores}},
                    @{Name="LogicalCores";Expression = {$_.NumberOfLogicalProcessors}},
                    Name
            }
        $steppablePipeline = $scriptCmd.GetSteppablePipeline($myInvocation.CommandOrigin)
        $steppablePipeline.Begin($PSCmdlet)
    } catch {
        throw
    }
}

process
{
    try {
        $steppablePipeline.Process($_)
    } catch {
        throw
    }
}

end
{
    try {
        $steppablePipeline.End()
    } catch {
        throw
    }
}
<#
 
.ForwardHelpTargetName CimCmdlets\Get-CimInstance
.ForwardHelpCategory Cmdlet
 
#>