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
  • Finding Events around A Date

    Often, you might want to browse all system events around a given date. Let's say a machine crashed at 08:47, and you'd like to see all events +/− 2 minutes around that time. Here is a script that does It for you: $deltaminutes = 2 $delta...
  • Auto-Connecting with Public Hotspot

    Many mobile phone service providers offer public hotspots at airports and public places. To connect, you typically need to browse to a logon page, and then manually enter your credentials. Here is a script that does this automatically. It is tailored...
  • Padding Strings Left and Right

    If you must make sure that a given string has a uniform width, then you can use .NET methods to pad the string appropriately: $mytext = ' Test ' $paddedText = $mytext . PadLeft ( 15 ) "Here is the text: '$paddedText'" $paddedText...
  • Formatting Numbers Easily

    Often, users need to format numbers and limit the number of digits, or add leading zeros. There is one simple and uniform strategy for this: the operator "-f"! Let's make sure a number has leading zeros: $number = 68 ' {0:d7} ' ...
  • Eliminating Duplicates

    Sort-Object has an awesome feature: with the parameter -Unique, you can remove duplicates: This can be applied to object results, as well. Check out this example: it will get you the latest 40 errors from your system event log: This may be perfectly fine...
  • Beware Of Hidden Password Requests

    You can run PowerShell code in any host, and Windows ships with powershell.exe and powershell_ise.exe. Many prefer the graphical ISE editor over the simple PowerShell console. Once you start using console applications, you must be aware that the ISE editor...
  • Tag Your Objects with Additional Information

    There may be the need to add additional information to command results. Maybe you get data from different machines and want to keep a reference where the data came from. Or, you want to add a date so you know when the data was created. Tagging objects...
  • Save Time With Select-Object -First!

    Select-Object has a parameter called -First that accepts a number. It will then return only the first x elements. Sounds simple, and it is. This gets you the first 4 PowerShell scripts in your Windows folder: Beginning in PowerShell 3.0, -First not only...
  • Expanding Variables in Strings

    To insert a variable into a string, you probably know that you can use double quotes like this: $domain = $env:USERDOMAIN $username = $env:USERNAME " $domain\$username " This works well as long as it is clear to PowerShell where your variables...
  • Using Aliases to Launch Windows Components

    PowerShell is not just an automation language but also an alternate user interface. If you do not like the graphical interface, educate PowerShell to open the tools you need via easy alias names. For example, to open the device manager, you could use...
  • Filtering Text-Based Command Output

    Comparison operators act like filters when applied to arrays. So any console command that outputs multiple text lines can be used with comparison operators. This example will use netstat.exe to get only established network connections, then to get only...
  • Keeping a Handle to a Process

    When you launch an EXE file, PowerShell will happily start it, then continue and not care about it anymore: If you'd like to keep a handle to the process, for example to find out its process ID, or to be able to check back later how the process performs...
  • Use $PSScriptRoot to Load Resources

    Beginning in PowerShell 3.0, there is a new automatic variable available called $PSScriptRoot. This variable previously was only available within modules. It always points to the folder the current script is located in (so it only starts to be useful...
  • Signing VBScript Files with PowerShell

    You probably know that Set-AuthenticodeSignature can be used to digitally sign PowerShell scripts. But did you know that this cmdlet can sign anything that This piece of code would load a digital certificate from a PFX file, then scan your home folders...
  • Correctly Filtering DateTime

    When you use Where-Object to filter information by date or time, this works actually very well--provided you use the correct filtering format. Do not use the format found in the results. To specify a date and or time, always use the culture-neutral management...
< Previous 1 2 3 4 5 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.