Note 2a: Don't worry if you get some access
denied messages. But do try run Example 1 again and see how
the script vastly reduced the number of temp files.
One reason to learn how to write PowerShell scripts rather than use the
GUI is that you can access areas where there is no Windows 7 GUI, or the
information is spread inconveniently over 2 or 3 menus.
Example 3: WMI ComputerSystem
Get-WmiObject win32_computersystem
Looking at Windows Management Instrumentation (WMI) is rather
like using a microscope to observe what's happening in the operating
system.
Guy
Recommends: WMI Monitor and It's Free!
Windows Management Instrumentation (WMI) is one of the hidden
treasures of Microsoft operating systems. Fortunately, SolarWinds
have created the
WMI Monitor so that you can examine these gems of
performance information for free. Take the guess work out of which WMI counters to use for applications like Microsoft Active Directory, SQL or Exchange Server.
Note 3b: PowerShell's backtick (`)allows the command to
wrap over onto the second line, put another way, without the backtick
PowerShell would assume two separate commands and the script would fail.
In this scenario you want to a PowerShell script to display all the latest
error messages, but you are not sure if the problem is recorded in the
System or Application log.
Example 5: Get-Eventlog with $_.
Clear-Host Get-Eventlog System -newest 2000 | Where {$_.entryType
-match "Error"} Write-Host "Application Log" Get-Eventlog
Application -newest 2000 | Where {$_.entryType -match "Error"}
Note 5a: Observe the neat $_. construction. It
means in the current pipeline, that is any Errors from Get-Enventlog's
output.
SolarWinds' Config Generator is a free tool, which puts you in charge of
controlling changes to network routers and other SNMP devices.
Boost your network performance by activating network device features
you've already paid for.
Guy says that for newbies the biggest benefit of this free tool is that
it will provide the impetus for you to learn more about configuring the SNMP
service with its 'Traps' and 'Communities'. Try Config Generator now - it's
free!
This Windows 7 PowerShell script will disable, or enable the
operating system's restore points. This script will show you how to create a PowerShell function.
When you create a PowerShell functions it's best to begin its name with an existing verbs such as
'get-' or 'set-'. Observe at the heart of this function is the switch
($RestoreOpt), which in turn calls on the WMI class systemrestore. It is this
parameter which provides your option to enable or disable the system restore.
One important point, you need to supply a different value for $sysName.
########################################## ## ## Author: Dave
Stone, Brooks Automation
## Date: 6 May 2011 ## Enables or disables the system restore on a
Windows 7 workstation ## ## Usage Set-SysRestore option computername
## ######################################
Function Set-SysRestore { param( $RestoreOpt = $(throw
"Please specify option, enable or disable"), $sysName = $(throw
"Please specify IP Address or Windows 7 computer name.") ) switch ($RestoreOpt)
{ "disable" {$SysRestore =
[wmiclass]"\\$sysname\root\default:systemrestore"
$SysRestore.Disable("C:\")} "enable"
{$SysRestore = [wmiclass]"\\$sysname\root\default:systemrestore"
$SysRestore.Enable("C:\")} }
} Set-SysRestore -RestoreOpt enable -SysName 192.168.1.20
Note 6a: This is a PowerShell scripts where you
need to 'Run as Administrator'.
Note 6b: Check the two options for the -RestoreOpt
parameter. It's the last line which puts the function
Set-SysRestore to work, and enables the system restore on the C:\.
Note 6c: To turn off your restore, issue the
reverse command: Set-SysRestore -RestoreOpt disable -SysName
YourComputer
Note 6d: Pay close attention to -SysName, your
Windows 7 or Vista machine is unlikely to have an IP address of
192.168.1.20. Alternatively, script the hostname.
»
Summary of Windows 7 PowerShell Scripts
I hope that these real-life examples of PowerShell in action will achieve
the following, give you a top-down understanding of what is possible, give
you a feel for the Verb-Noun cmdlets, and how you can join them with a
simple pipe (|).
If you like this page then please share it with your friends
Guy Recommends:
SolarWinds' NPM - Network Performance Monitor
SolarWinds' performance monitor is designed for detecting network outages,
making it easy to see what's working, and what needs your attention.
This utility guides you through creating network maps; it also helps
identifying whether the
root cause is faulty equipment, or resource overload. Give NPM a try.