Power Tips

Share |

Join PowerShell.com!
Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Powershell Plus


13 Free SQL Tools from Idera


Free Ebook: Mastering Powershell

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
  • Searching in Different Domains

    When you use the ADSISearcher type accelerator to find Active Directory accounts, it defaults to the current domain you are logged on to. If you need to find an account in a different domain, make sure you define the search root accordingly. This example...
  • Obfuscating Credentials

    How can you securely embed confidential passwords in a PowerShell script? You can't. But you can make it harder for people to discover the secret. Here is a code generator script that is designed to run inside the PowerShell ISE editor: # ask for...
  • Change Desktop Wallpaper

    To change the current desktop wallpaper and make this change effective immediately, PowerShell can tap into the Windows API calls. Here is a function that changes the wallpaper immediately: function Set-Wallpaper { param ( [ Parameter ( Mandatory = $true...
  • 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 $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...
  • 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...
  • 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...
  • 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...
  • 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 = '...
  • 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.