Power Tips

Share |

Join PowerShell.com!
Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Award-winning PowerShellPlus


Admin Guide to PowerShell Remoting


Mastering PowerShell eBook

Welcome to the archive of tips delivered through Tobias' Tip of the Day RSS Feed and Your Power Tip of the Day email. Subscribe in the sidebar to get the latest tips!

Sort by: Most Recent | Most Viewed | Most Commented
  • Logging All Errors

    In a previous tip you have seen that cmdlet errors can only be caught by an error handler if the -ErrorAction is set to "Stop". Doing this alters the way the cmdlet works, though. It will then stop at the first error encountered. Take the next...
  • Catching Non-Terminating Errors

    Non-terminating errors are errors that are handled by a cmdlet internally. Most errors that can occur in cmdlets are non-terminating. You cannot catch these errors in an error handler. So although there is an error handler in this sample, it will not...
  • Hiding Terminating Errors

    Occasionally, you may have noticed that cmdlets throw errors although you specified "SilentlyContinue" as -ErrorAction. The -ErrorAction parameter can only hide non-terminating errors (errors that originally were handled by the cmdlet). Any...
  • Getting Events From All Event Logs

    Recently, a reader asked how to retrieve all events from all event logs from a local or remote system, and optionally save them to file. Here is a potential solution: # calculate start time (one hour before now) $Start = ( Get-Date ) - ( New-Timespan...
  • Running Background Jobs Efficiently

    Using background jobs to run tasks concurrently often is not very efficient as you might have seen in a previous tip. Background job performance worsens with the amount of data that is returned by a background job. A much more efficient way uses in-process...
  • Parallel Processing in PowerShell

    If a script needs some speed-up, you might find background jobs helpful. They can be used if a script does a number of things that also could run concurrently. PowerShell is single-threaded and can only do one thing at a time. With background jobs, additional...
  • Converting Ticks into Real Date

    Internally, Active Directory uses ticks (100 nanosecond units since 1601) to represent date and time. It has been hard in the past to convert these huge numbers into human readable date and time. Here is a much easier way: [ DateTime ] :: FromFileTime...
  • Logging Script Runtime

    If you'd like to monitor how long a script takes to run, you could use Measure-Command, but this cmdlet is for diagnostic purposes only and omits any script output. Another approach just takes two snapshots and at the end, calculates the time difference...
  • Fixing Encoding for Excel CSV

    When you save Microsoft Excel data as CSV, unfortunately the encoding does not match the default encoding used by Import-Csv. So when you import the CSV file into PowerShell, special characters may be garbled, no matter what encoding you specify. Here...
  • Reading All Text

    You can use Get-Content to read in any plain text file. However, Get-Content will return the file content line by line, and you get back a string array. The line endings are consumed. To read in a text file in one big chunk, beginning with PowerShell...
  • Storing Secret Data

    If you wanted to store sensitive data in a way that only you could retrieve it, you can use a funny approach: convert some plain text into a secure string, then convert the secure string back, and save it to disk: $storage = " $env:temp\secretdata...
  • Using Encrypting File System (EFS) to Protect Passwords

    If you absolutely need to hardcode passwords and other secrets into your scripts (which you should avoid for obvious reasons), then you might still be safe when you encrypt the script with the EFS (Encrypting File System). Encrypted scripts can only be...
  • Testing UNC Paths

    Test-Path can test whether or not a given file or folder exists. This works fine for paths that use a drive letter, but can fail with pure UNC paths. At its simplest, this should return $true, and it does (provided you did not disable your administrative...
  • Enabling PowerShell Remoting

    If you'd like to use PowerShell Remoting to execute commands and scripts on another machine, then you need to enable Remoting on the target side with full Admin privileges: On the client side, you do not need to do anything special when you are in...
  • Enabling Classic Remoting

    Many cmdlets have built-in remoting capabilities, for example Get-Service and Get-Process both have the parameter -ComputerName, and so does Get-WmiObject. However, to actually use these cmdlets remotely, the remoting technique employed by the cmdlets...
1 2 3 4 5 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.