Running Commands

Let’s take a look at the kind of commands you can send to PowerShell. Always remember: it does not matter how you send these commands to PowerShell – whether you use the PowerShell Console, the ISE Editor, or any other PowerShell host. Anything you see here works in any PowerShell host because they all talk to the same PowerShell.

Uh! PowerShell Shows Red Errors!
You will see red error messages eventually. They are a frequent companion, even for experienced PowerShellers. “But this ship can’t sink!”Don’t feel intimidated: it’s PowerShells way of saying “Excuse me? Dunno what you mean!”

You just need to actually read these messages. Often, they are pretty good at explaining what’s wrong.  Admittedly, they are a bit tight and technical – because IT people’s hair is frequently on fire, and they just don’t have the time to read through poetry.

PS C:\> 1/0
Attempted to divide by zero.
At line:1 char:1
+ 1/0
+ ~~~
    + CategoryInfo          : NotSpecified: (:) [], RuntimeException
    + FullyQualifiedErrorId : RuntimeException
 
PS C:\> hello? Anyone home?
hello? : The term 'hello?' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the 
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ hello? Anyone home?
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (hello?:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Now that we have this out of the way, let’s start to make friends with PowerShell:

Doing the Math

Fun with Shortcuts

Using Variables

Running Applications

Running PowerShell Cmdlets

Executing .NET Code