header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

WMI Count for win32_processor
Last Post 25 Nov 2008 02:49 PM by MattG. 7 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
MattGUser is Offline
New Member
New Member
Posts:20
Avatar

--
24 Nov 2008 09:18 PM  
I am looking to get CPU Name and CPU count from the Win32_processor object and export them to a csv.

Here is what I am looking at:

add-pssnapin Quest.ActiveRoles.ADManagement
    Connect-QADService -Service DCSRV1
    $AD = Get-QADComputer -ldapfilter '(&(!(userAccountControl:1.2.840.113556.1.4.803:=2))(|(operatingSystem=*Server*)(&(operatingSystem=*NT*))))'|Sort-Object

$field1 = @{Name="name";Expression={$_.SystemName}}
$field2 = @{Name="CpuName";Expression={$_.Name}}
$field3 = @{Name="NoOfCores";Expression= {$srv.Count}}

$AD |foreach {
   
    $name = $_.name
    $ping = gwmi win32_pingstatus -filter "address='$name'"
    if($ping.statusCode -eq 0){
         $srv = gwmi win32_processor -computername $name|select $field1, $field2, $field3
          }
    } | export-csv c:\cpu.csv -noType 


This is obviously not working.  How can I get the Count in a variable so that I can produce a CSV with the 3 fields listed?

Thanks,
-MattG
ShayUser is Offline
Basic Member
Basic Member
Posts:271
Avatar

--
24 Nov 2008 10:18 PM  
You need to refernece the NumberOfCores property:

$field3 = @{Name="NoOfCores";Expression= {$_.NumberOfCores}



This line assign a variable but it don't writes it back to the pipline:

$srv = gwmi win32_processor -computername $name|select $field1, $field2, $field3



You can change it to:

$srv = gwmi win32_processor -computername $name|select $field1, $field2, $field3
$srv


or simply remove the assignment:

gwmi win32_processor -computername $name|select $field1, $field2, $field3





Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
MattGUser is Offline
New Member
New Member
Posts:20
Avatar

--
25 Nov 2008 12:17 PM  
NumberOfCores is only available in Vista and Windows 2008 (I am assuming) as it definitely is not in Windows 2003 R2 or older.  That is why I am trying to do a count of the rows returned per server object to at least know the # of cores.

Can this be done?

Thanks,
-MattG
ShayUser is Offline
Basic Member
Basic Member
Posts:271
Avatar

--
25 Nov 2008 12:38 PM  
The win32_computersystem class has a NumberOfProcessors property

gwmi win32_computersystem -ComputerName computer | ft NumberOfProcessors
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
ShayUser is Offline
Basic Member
Basic Member
Posts:271
Avatar

--
25 Nov 2008 12:47 PM  
There is another option using environment variables. To get it locally:

PS > $env:NUMBER_OF_PROCESSORS

Remotley:

PS > gwmi win32_environment -filter "name='NUMBER_OF_PROCESSORS'" -computer computerName | ft VariableValue
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
MattGUser is Offline
New Member
New Member
Posts:20
Avatar

--
25 Nov 2008 01:28 PM  
I am now grabbing the # of procs via the ComputerSystem object as per your suggestion.  Unfortunately,  that object does not include the CPUName.  So I still need to get this from win32_processor which is what I am doing with this script:

$field1 = @{Name="name";Expression={$_.SystemName}}
$field2 = @{Name="CpuName";Expression={$_.Name}}


$AD |foreach {
    
    $name = $_.name
    $ping = gwmi win32_pingstatus -filter "address='$name'"
    if($ping.statusCode -eq 0){
        $srv = gwmi win32_processor -computername $name
        $srv | select $field1,$field2 -Unique
          }
    } | export-csv c:\cpu.csv -noType 


What I cannot figure out is how to trim the output of the $_.Name field.  Currently it is output like this:
"       Xeon 5110     @2.4GHZ     "

I found the TrimStart and TrimEnd commands,  but don't know how to apply them to $field2 without destroying the required header info needed for the CSV?

I appreciate all of the assistance.

Thanks,
-Matt
ShayUser is Offline
Basic Member
Basic Member
Posts:271
Avatar

--
25 Nov 2008 01:49 PM  
Try trim() ;-)

Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
MattGUser is Offline
New Member
New Member
Posts:20
Avatar

--
25 Nov 2008 02:49 PM  
Perfect!

Thanks,
-MattG
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer