Powershell Script To Update Computer Description Registry
Windows Server 2003, Windows Server 2003 SP1 and SP2, and Windows Server 2003 R2 retired content. The content you requested has already retired. It's available to.
Power. Shell Script Lets You Check Patches' Status. Executive Summary: Kb.
Windows Power. Shell script that uses Windows Management Instrumentation (WMI) to check whether a specific patch is installed on computers and provides the results in an onscreen report. To make it easier to spot problematic computers, this Windows Power. Shell script displays the names of the computers that aren't patched in red and the names of the computers that are successfully patched in green. Because SUS doesn’t have any reporting tools, it’s difficult to determine which machines aren’t patched. Thus, administrators at my company have been using KB. Windows client machines. Although KB. vbs works well, I decided to rewrite the script in Power.
Shell last July because I wanted to experience the power in Power. Shell firsthand. More important, I never want to stop learning. I feel it’s important to learn to apply Power. Shell to current problems.

The result is kb. Like KB. vbs, kb. If a PC is online, the script determines whether the specified patch exists and reports the results. To make it easier to spot problematic computers, the names of the computers that aren’t patched are displayed in red and the names of the computers that are successfully patched are displayed in green. The script also reports ping failures.
Figure 1 shows a sample input file. The path to this input file and the patch to search for are specified on the command line when you launch the script. The launch syntax is powershell.
Path\kb. ps. 1Input. File. Path kbxxxxxx where Path is the folder in which kb. Input. File. Path is the pathname of the input file, and kbxxxxxx is the ID of patch you want to search for. Alternatively, if kb.
Power. Shell directory (e. D: \Power. Shellscripts), you can type Path> powershell .\kb. Path is the folder in which kb. ID of patch you want to search for.
As Listing 1 shows, kb. Power. Shell scripts. The first command $erroractionpreference = `“Silently. Continue”completely suppresses error output. By default, when an error occurs, Power. Shell issues an error message, then continues to the next line. When you set the $Error- Action.
This Microsoft Support page provides downloads of the Windows Management Framework that includes WinRM 2.0, Windows PowerShell 2.0, and BITS 4.0. These files are for. Scripts can run. Requires that all scripts and configuration files be signed by a trusted publisher, including scripts that you write on the local computer.
Preference automatic variable to Silently. Continue, the processing continues but an error message isn’t issued.
Suppressing error messages eliminates distractions for the administrators when they’re reviewing the onscreen patch- status report. Because kb. The second command clear- host clears the Power. Shell window. Typically, the Clear- Host function is used at the end of scripts, but I used it at the beginning of kb. Once again, that helps generate a clean, easily readable electronic report for administrators to review. After clearing the Power.
Shell window, kb. If there aren’t exactly two, it displays the syntax for the launch command. Using the Get- Content cmdlet, kb.
For each computer, the script uses Windows Management Instrumentation’s (WMI’s) Win. The Get- Wmi. Object cmdlet with the - query parameter is used to execute the WMI Query Language (WQL) statement that pings the machine. The script determines whether the ping succeeded (i.
Status. Code property of the Win. If the ping didn’t succeed, kb. Write- Host cmdlet to log the computer’s name and the message Ping failed.
I didn’t use the Write- Error cmdlet to write the ping- failure information because it mangles the information almost to the point of being unreadable. If the ping succeeded, the script uses the Get- Wmi. Object cmdlet with WMI’s Win. The script pipes the results to the Where- Object cmdlet, which filters the results for information about the specified patch. The results of that filter operation are then piped to the Select- Object cmdlet, which retrieves the patch’s Hot.
Fix. ID and Description properties. As callout A shows, kb. Hot. Fix. ID property’s value is the same as the $kb variable’s value.
If they match, the script writes the computer’s name and the patch’s description in green text. If they don’t match, the script writes the computer’s name and the message Patch not found in red text. To write the patch- status information, the script again uses Write- Host. This cmdlet writes information directly to the host interface, which makes the output unusable for pipelining. However, we don’t need the output piped anywhere. Equally important, if the script were to let standard output handle the patch display, you’d get lots of pages containing extraneous information. For our purposes (i.
Write- Host works best. As you can see, there’s nothing fancy about kb. However, it’s shorter and faster than KB. Plus, the color- coded results make the report easier to read and more presentable for administrators. See Associated Figure.
Create a list of local administrators with Power. Shell – 4sysops< # . Synopsis Gets membership information of local groups inremote computer . A Different Gospel Updated Edition Hotel. Description Thisscript by defaultqueries the membership details of local administrators group on remote computers. Proceeding with next computer!