# Listing 9: ProcessorInfo3.ps1 # Define the JScript function to the format string. $js = 'function formatInfo(procInfo) { strInfo = procInfo.toString() trimInfo = strInfo.replace(/(^\s*)|(\s*$)/g, "") return trimInfo.replace(/\(R\)/g, "(r)") }' # Create the COM scriptControl object. # Assign the object to the $sc variable. $sc = new-object -com scriptControl # Specify JScript as the scripting language. $sc.language = "jscript" # Don't display message boxes. $sc.allowUI = $false # Add the JScript code to the scriptControl object. $sc.addCode($js) # Create a code object. $co = $sc.codeObject # Create the WMI object to retrieve the processor data. # Assign the object to the $wmiObject variable. $wmiObject = get-wmiobject -class "Win32_Processor" ` -namespace "root\CIMV2" -computername "." write-host # Create a foreach loop to display each line of data. # Use the formatInfo function to format the data. foreach ($item in $wmiObject) { write-host "Manufacturer:" $co.formatInfo($item.Manufacturer) write-host "Name:" $co.formatInfo($item.Name) write-host "Description:" $co.formatInfo($item.Description) write-host "Clock speed:" $co.formatInfo($item.MaxClockSpeed) write-host }