Guy recommends:
A free trial of
WebHelpDesk

Solarwinds Free WebHelpDesk

Install a ticket-based help desk system from SolarWinds. Download your free trial

Windows PowerShell Tips

Windows PowerShell Tips

Here is a selection of tips to help you get started with Windows PowerShell.

Top 10 PowerShell Tips

  1. Get into the rhythm of: Verb-Noun pairing.
  2. Help is excellent, try: Get-Help Get-Command -Full
  3. Understand the power and flexibility of the piping the output of one command, (|) into the input of second.
  4. Make a list of PowerShell's nouns.  Begin with with: service, process and eventlog.
  5. Create function cmdlets to build, and then store, your commands.
  6. Get-Member is very useful for investigating the properties of an object, for example, Get-Process | Get-Member  (Remember the pipe symbol between the two commands.)
  7. You can access the Registry as a namespace or a file system.  Try this: Get-Psdrive
  8. Brackets are important in PowerShell for controlling expressions, {especially those known as squiggly or curly brackets}.
  9. There are several looping commands, for example, Do While and ForEach.
  10. Redirect the results of your commands to a file, the verb is 'out' and the noun is 'file', making the command: out-File, for example:
    Get-Service | out-File servlist.txt.

SolarWinds Firewall Browser Solarwinds Free Firewall Browser

Here is an utility where you can review firewall settings such as access control lists (ACL), or troubleshoot problems with network address translation (NAT).

Other reasons to download this SolarWinds Firewall Browser include managing requests to change your firewall settings, testing firewall rules before you go live, and querying settings with the browser's powerful search options.

Guy recommends that you download a copy of the SolarWinds free Firewall Browser.

More PowerShell Tips

  1. Take the time to locate and configure your: Profile.ps1.
  2. Concatenating text is easy, simply use plus (+).  In PowerShell, adding text is exactly the same as adding numbers.
  3. Observe PowerShell's efficiency by experimenting with WmiObject as opposed to WMI's VBScript equivalent
  4. You can create $Variables and then access their dot .commands.  $Variable.count
  5. Alias.  Check the built-in Aliases.  Consider the pros an cons of creating your own Aliases.
  6. Get-Childitem (dir), also has the built-in alias of gci.
  7. -WhatIf  I have not seen this safety mechanism in other scripting languages.  The idea is to have a test or trial run and report what will happen if you really did issue the command.
  8. -Confirm  This is another checking mechanism.
  9. Naturally, PowerShell supports wildcards for example, Get-Service b*
  10. Many of the old VBScript objects can be created with new-object, for example:
    new-object -ComObject "InternetExplorer.Application"
  11. The 'If' construction is supported, also -switch  (Rather like Select Case in VBScript)
  12. Error messages are clearer than usual; get into the habit of reading them!
  13. A useful parameter is -errorAction inquire, and also -errorAction SilentlyContinue
  14. When you install PowerShell, remember to also get .NET Framework.
  15. Favour the ISE version of PowerShell rather than the command line.

Guy Recommends: Free WMI Monitor for PowerShellSolarwinds Free WMI Monitor for PowerShell

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft's operating systems.  Fortunately, SolarWinds have created a Free WMI Monitor so that you can discover these gems of performance information, and thus improve your PowerShell scripts.

Take the guess work out of which WMI counters to use when scripting the operating system, Active Directory, or Exchange Server. Give this WMI monitor a try - it's free.

Download your free copy of WMI Monitor

Pure PowerShell Window Tips

Remember Doskey?  The up and down arrows also work in the PowerShell, very handy for cycling through previous commands.  In addition, F7 (Function key 7) produces a history of the last 50 commands.

Just as with CMD, you can copy and paste into the shell.  What I do is use the top left icon Windows PowerShell Icon and from the drop-down menu select, Edit -->, Paste.

Increase the size of the PowerShell box

Microsoft PowerShell Increase the size of the MSH box

With 1024 x 768 screen resolution, you could increase the Windows Size:  a) Width to 110 b) Height to 55.

Copy and Paste Other People's Scripts!

Here is the copy and paste method to execute PowerShell instructions at the command line.

  • Launch PowerShell
  • Copy the code you wish to run into memory
    (For instance, from Example 1a)
  • Right-click on the PowerShell symbolPowerShell Scripts How to Copy and Paste
  • Edit --> Paste
  • Press enter to execute the code
  • See screenshot to the right
 

More PowerShell Tips

a)  .Net Framework
Research .Net Framework classes.  Knowledge of .Net Framework helps to understand the object nature of PowerShell. 

b)  FT or Format-Table
There is no doubt that a well formatted output is easier to understand.  PowerShell has astonishing flexibility in displaying data.

If you like this page then please share it with your friends

 


See more Microsoft PowerShell tutorials

PowerShell Tutorials  • Methods  • Cmdlets  • PS Snapin  • Profile.ps1  • Exchange 2007

Command & Expression Mode  • PowerShell pipeline (|)  • PowerShell 'where'  • PowerShell 'Sort'

Windows PowerShell Modules  • Import-Module  • PowerShell Module Directory 

If you see an error of any kind, do let me know.  Please report any factual mistakes, grammatical errors or broken links.

 *


Custom Search

Site Home

Guy Recommends: WMI Monitor for PowershellSolarwinds WMI Monitor

Windows Management Instrumentation (WMI) is most useful for PowerShell scripting.

SolarWinds have produced this Free WMI Monitor to take the guess work out of which WMI counters to use for applications like Microsoft Active Directory, SQL or Exchange Server.

Download your free copy of WMI Monitor

Author: Guy Thomas Copyright © 1999-2016 Computer Performance LTD All rights reserved.

Please report a broken link, or an error to: