Guy recommends :
Free Permissions
Analyzer Tool

Solarwinds Free Download of Permissions Analyzer

 

View the effective permissions for a folder or shared drive. Free download try it now!


Microsoft PowerShell Syntax

Introduction to Microsoft PowerShell's Syntax

This section is dedicated to explaining PowerShell's individual syntactic elements.  I  also regard these topics as reference material for that time when you forget how to choose the correct type of bracket, or when a single quote does not get the job done.

Microsoft PowerShell Syntax Topics

Pure Syntax

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

The Significance of PowerShell's Brackets

Parenthesis Brackets ()
Curved () parenthesis stype brackets are used for compulsory arguments.  Take for example a ForEach loop the first section is like Foreach ($Item in $Items).  Microsoft call this 'control structure'.

Braces Brackets {}
These curly brackets are typically employed in block statements; for example:
| Where {$_.name -Like "Network"}

Square Brackets []
This is probably the least important, and least used brackets, that's because they define optional items, for example:
Get-Process [W]*

See more on PowerShell's brackets »

PowerShell Conditional Operators

PowerShell has three main conditional operators, -Match, -Like and -Contains.

# PowerShell Syntax example to demonstrate -Match
# Author: Guy Thomas
# May 2010 tested on PowerShell v 1.0 and 2.0

$WMI = Get-WmiObject -List | where-Object {$_.name -Match "network"}
$WMI | Format-Table name, Properties -auto
Write-Host $WMI.count "WMI objects contain the word network"

See more on PowerShell's Conditional Operators »

Example of PowerShell's Comparison Operators

At first glance, one of the strangest comparison operator in PowerShell is -eq.  While the equals sign '=' is still needed for declaring variables, in most other cases you need -eq, or for PowerShell not equal -ne.  Once you warm to this theme, then -gt -lt seem a logical continuation.  Consequently, abandon > and <, instead employ -gt (greater than) or -lt (less than).

# PowerShell script to list .exe under the Windows folder
$Dir = Get-Childitem C:\windows\ -recurse
$List = $Dir | where {$_.extension -eq ".exe"}
$List | Format-Table Name, CreationTime -auto

See more examples of comparison operators »

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 Syntax

Contents of My PowerShell Cmdlet Pages

Each topic has its own 'how to' instructions and also 'Learning points'.  As a result you will be able to modify my examples to suit your situation.  The only pre-requisite is that you must download the correct version of PowerShell and .Net Framework for your operating system.  Microsoft's site has separate versions of PowerShell for XP, Windows Server 2003 and Vista.  In the case of Windows 7 and later, PowerShell is built-In but you need to 'Add Feature'.

Other Microsoft PowerShell Topics

Summary of PowerShell Syntax

The pages in this section will help you with PowerShell's individual syntactic elements.  I regard these topics as reference material for that time when you forget how to choose the correct type of bracket, or when a single quote does not get the job done.

Another use of this page is to investigate new parameters or switches for well-known commands, for example -recurse as in: Get-Childitem -recurse.

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

 


See more Windows PowerShell sections

PowerShell Home   • Introduction  • Dreams   • 3 Key Commands   • Free Permissions Analyzer

PowerShell Real-life Examples   • PowerShell Syntax   • PowerShell 2.0   • PowerShell v 3.0

Windows PowerShell   • PowerShell Techniques   • PowerShell ISE  • Contact

Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.

Download my ebook:Getting Started with PowerShell
Getting Started with PowerShell - only $9.25

You get 36 topics organized into these 3 sections:
   1) Getting Started
   2) Real-life tasks
   3) Examples of Syntax.

In addition to the ebook, you get a PDF version of this  Introduction to PowerShell ebook  It runs to 120 pages of A4.

 *


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-2013 Computer Performance LTD All rights reserved.

Please report a broken link, or an error to: