Here is
a selection of tips to get started with Windows PowerShell.
PowerShell Tips
When you install PowerShell, remember to also get .NET
Framework.
Get into the rhythm of: verb-Noun pairing.
Take the time to locate and configure your: Profile.ps1.
Create cmdlets to build, and then store, your commands.
Build a list of nouns. Begin with with: service, process and eventlog.
Understand the power and flexibility of the piping the output of one
command, (|) into the input of second.
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.
Observe PowerShell's efficiency by experimenting with WmiObject as opposed to
WMI's VBScript equivalent
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.)
You can access the Registry as a namespace or a file system.
Try this: get-Psdrive
Brackets are important in PowerShell for controlling expressions, {especially those known as squiggly or curly brackets}.
Concatenating text is easy, simply use plus (+). In
PowerShell, adding text is exactly the same as adding numbers.
You can create $Variables and then access their dot .commands.
$Variable.count
Help is excellent, try: get-Help get-Command
Alias. Check the built-in Aliases. Consider the pros an cons of creating your own Aliases.
get-Childitem (dir), also has the built-in alias of gci.
-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.
-confirm This is another checking mechanism.
Naturally, PowerShell supports wildcards for example, get-Service b*
Error messages are clearer than usual; get into the habit of reading them!
Many of the old VBScript objects can be created with new-object, for example: new-object -ComObject "InternetExplorer.Application"
The 'If' construction is supported, also -switch (Rather like Select Case in VBScript)
There are several looping commands, for example,
Do While and ForEach
A useful parameter is -erroraction inquire
For more information append -verbose
˚
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 and from the drop-down menu
select, Edit -->, Paste.
Increase the size of the
PowerShell 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 symbol
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 see an error of any kind, do let me know. Please report any factual mistakes, grammatical errors or broken links, I will be happy to not only to correct the fault, but also to give you credit.