GAPTHEGURU

Geek with special skills

Powershell

PowerShell Tips

  1. When you install PowerShell, remember to also get .NET Framework.
  2. Get into the rhythm of: verb-Noun pairing.
  3. Take the time to locate and configure your: Profile.ps1.
  4. Create cmdlets to build, and then store, your commands.
  5. Build a list of nouns.  Begin with with: service, process and eventlog.
  6. Understand the power and flexibility of the piping the output of one command, (|) into the input of second.
  7. 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.
  8. Observe PowerShell’s efficiency by experimenting with WmiObject as opposed to WMI’s VBScript equivalent
  9. 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.)
  10. You can access the Registry as a namespace or a file system.  Try this: Get-Psdrive
  11. Brackets are important in PowerShell for controlling expressions, {especially those known as squiggly or curly brackets}.
  12. Concatenating text is easy, simply use plus (+).  In PowerShell, adding text is exactly the same as adding numbers.
  13. You can create $Variables and then access their dot .commands.  $Variable.count
  14. Help is excellent, try: Get-Help Get-Command
  15. Alias.  Check the built-in Aliases.  Consider the pros an cons of creating your own Aliases.
  16. Get-Childitem (dir), also has the built-in alias of gci.
  17. -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.
  18. -confirm  This is another checking mechanism.
  19. Naturally, PowerShell supports wildcards for example, Get-Service b*
  20. Error messages are clearer than usual; get into the habit of reading them!
  21. Many of the old VBScript objects can be created with new-object, for example:
    new-object -ComObject “InternetExplorer.Application”
  22. The ‘If’ construction is supported, also -switch  (Rather like Select Case in VBScript)
  23. There are several looping commands, for example, Do While and ForEach
  24. A useful parameter is -errorAction inquire, and also -errorAction SilentlyContinue
  25. For more information append -verbose

No comments yet.

Leave a comment