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
  • Getting DNS IP Address from Host Name

    There is a tiny .NET function called GetHostByName() that is vastly useful. It will look up a host name and return its current IP address: [ System.Net.DNS ] :: GetHostByName ( ' someName ' ) With just a simple PowerShell wrapper, this is turned...
  • Speaking English and German (and Spanish, and you name it)

    Windows 8 is the first operating system that comes with fully localized text-to-speech engines. So you can now have PowerShell speak (and curse) in your mother tongue. At the same time, there is always an English engine, so your computer is now bilingual...
  • Use Open File Dialog

    All PowerShell versions To add some sophistication to your script, here is a simple function that opens the OpenFile dialog and lets the user pick a file. function Show-OpenFileDialog { param ( $Title = ' Pick a File ' , $Filter = ' All|*...
  • Cmdlets to Manage MSI Packages

    PowerShell 2.0 and later Anyone who needs to manage MSI installer packages may benefit from an open source project found here: http://psmsi.codeplex.com/ . Simply download the PowerShell module – it comes as an MSI installer package itself. Make...
  • Credential Obfuscator

    PowerShell ISE 3.0 and later While it is generally not recommended to hard code passwords in scripts, there are sometimes scenarios where this is done. Rather than hard coding plain text passwords, at least an effort should be made to obfuscate passwords...
  • Copying Command Line History

    All PowerShell versions To preserve all the PowerShell commands that you entered in a PowerShell session, check out this one liner: ( Get-History ) . CommandLine | clip.exe It copies all commands to the clipboard. From there, you can paste them into PowerShell...
  • Testing for Valid Date

    If you need to test whether some information resembles a valid date format, here is a test function: function Test-Date { param ( [ Parameter ( Mandatory = $true ] $Date ) (( $Date -as [ DateTime ]) -ne $null ) } It uses the -as operator to try and convert...
  • Create New Local Admin Account on the Fly

    Ever needed a new local administrator account for testing purposes? Provided you are already Administrator, and you opened a PowerShell with full Administrator privileges, adding such a user is a matter of just a couple of lines of code: $user = '...
  • Multiple Assignments in One Line

    When you assign something to a variable, you can enclose the expression in braces. This will also output the data. Have a look: $a = Get-Service ( $a = Get-Service ) See the difference? The second line will not only assign the results from Get-Service...
  • 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...
  • 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...
  • 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...
  • 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...
  • Finding Default MAPI Client

    Your MAPI client is the email client that by default is used with URLs like "mailto:". To find out if there is a MAPI client, and if so, which one it is, here is a function that retrieves this information from the Windows Registry. function...
  • 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...
« First ... < Previous 3 4 5 6 7 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.