# Listing 8: ProcessorInfo2.ps1 # ******* BEGIN CALLOUT A ******* # Define the VBScript function to the format string. $vbs = 'function formatInfo(procInfo) formatInfo = replace(trim(procInfo), "(R)", "(r)") end function' # ******* END CALLOUT A ******* # ******* BEGIN CALLOUT B ******* # Create the COM scriptControl object. # Assign the object to the $sc variable. $sc = new-object -com scriptControl # Specify VBScript as the scripting language. $sc.language = "vbscript" # Don't display message boxes. $sc.allowUI = $false # Add the VBScript code to the scriptControl object. $sc.addCode($vbs) # Create a code object. $co = $sc.codeObject # ******* END CALLOUT B ******* # ******* BEGIN CALLOUT C ******* # 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 } # ******* END CALLOUT C *******