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, and also -errorAction SilentlyContinue
- For more information append -verbose
No comments yet.
-
Archives
- June 2013 (2)
- December 2012 (4)
- November 2012 (1)
- August 2012 (8)
- July 2012 (1)
- June 2012 (3)
- May 2012 (14)
- April 2012 (8)
- March 2012 (7)
- February 2012 (4)
- January 2012 (9)
- December 2011 (6)
-
Categories
-
RSS
Entries RSS
Comments RSS
Leave a comment