# Listing 10: ProcessorInfo4.ps1 # ******* BEGIN CALLOUT A ******* # Create the COM scriptControl object. # Assign the object to the $sc1 variable. $sc1 = new-object -com scriptControl # Specify VBScript as the scripting language. $sc1.language = "vbscript" # Don't display message boxes. $sc1.allowUI = $false # Add the VBScript function to the scriptControl object. $sc1.addCode(' function replaceStr(procInfo) replaceStr = replace(procInfo, "(R)", "(r)") end function ') # Create a code object. $vbs = $sc1.codeObject # ******* END CALLOUT A ******* # ******* BEGIN CALLOUT B ******* # Create the COM scriptControl object. # Assign the object to the $sc2 variable. $sc2 = new-object -com scriptControl # Specify JScript as the scripting language. $sc2.language = "jscript" # Don't display message boxes. $sc2.allowUI = $false # Add the JScript function to the scriptControl object. $sc2.addCode(' function trimStr(procInfo) { strInfo = procInfo.toString() return strInfo.replace(/(^\s*)|(\s*$)/g, "") } ') # Create a code object. $js = $sc2.codeObject # ******* END CALLOUT B ******* # ******* BEGIN CALLOUT C ******* # Create the WMI object to retrieve the processor data. # Assign the object to $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:" $vbs.replaceStr($js.trimStr($item.Manufacturer)) write-host "Name:" $vbs.replaceStr($js.trimStr($item.Name)) write-host "Description:" $vbs.replaceStr($js.trimStr($item.Description)) write-host "Clock speed:" $vbs.replaceStr($js.trimStr($item.MaxClockSpeed)) write-host } # ******* END CALLOUT C *******