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
  • Checking Windows Updates

    To check all installed updates on a Windows box, there is a COM library you can use. Unfortunately, this library isn't very intuitive to use, nor does it work remotely. So here is a PowerShell function called Get-WindowsUpdate. It gets the locally...
  • Finding AD Accounts Easily

    All PowerShell versions You do not necessarily need additional cmdlets to search for user accounts or computers in your Active Directory. Provided you are logged on to the domain, simply use this: $ldap = ' (&(objectClass=computer)(samAccountName...
  • Getting Excuses Automatically

    Tired of inventing lame excuses yourself? Then here's a script that gets you a new excuse any time you call Get-Excuse! All you need is Internet access: function Get-Excuse { $url = ' http://pages.cs.wisc.edu/~ballard/bofh/bofhserver.pl '...
  • Pinging Computers

    There are multiple ways how you can ping computers. Here is a simple approach that uses the traditional ping.exe but can be easily integrated into your scripts: function Test-Ping { param ([ Parameter ( ValueFromPipeline = $true )] $Name ) process { ...
  • ExpandProperty rocks - sometimes

    Select-Object will select the object properties that you want to see. So it removes all properties you did not specify, but it always returns an object: Get-Process | Select-Object Name Often, you are not interested in an object but prefer the content...
  • Using OpenFile Dialog

    You can use this code to open a standard OpenFile dialog in your PowerShell scripts: [ System.Reflection.Assembly ]:: LoadWithPartialName ( "System.windows.forms" ) | Out-Null $dialog = New-Object System.Windows.Forms.OpenFileDialog $dialog...
  • Creating Calendars (and Lists of Dates)

    Here's a code snippet that creates DateTime ranges. Just specify a year and a month, and the script produces a DateTime object for each day in that month: $month = 8 $year = 2013 1 .. [ DateTime ] :: DaysInMonth ( $year , $month ) | ForEach-Object...
  • Creating Readable CSV-and HTML-Output

    When you convert PowerShell results to CSV or HTML output, you may have discovered that some properties don't display correctly. PowerShell cannot correctly convert arrays to strings and instead displays the array data type. Here's a sample: #...
  • Turning CSV-Files into "Databases"

    Let's assume you have a CSV file with information that you need to frequently look up. For example, the CSV file may contain server names and certain configuration settings for them. To easily look up items in your CSV file, you can turn it into a...
  • Running Portions of Code Elevated

    Let's assume your script may or may not need to do a privileged operation, for example write a value to a HKEY_LOCAL_MACHINE branch, depending on some prerequisites. Instead of having to run the entire script with Administrator privileges, you can...
  • Executing PowerShell on Computer Lock

    PowerShell can respond to system events such as locking or unlocking a session. Here is a fun sample. Provided you have your sound card turned on, your computer will say good-bye when you press WIN+L and welcome you back when you log on again: function...
  • Creating Range of Letters

    PowerShell can easily provide a range of numbers, but creating them is not that easy - unless you convert ascii codes into characters: 65..90 | Foreach-Object { "$([char]$_):" } ReTweet this Tip!
  • Reading Text Files Fast

    Let's assume you want to read a large text file. Let's create one: Get-Process | Export-CliXML $home \data. xml (Dir $home \data. xml | Select-Object -expandProperty Length) / 1MB It should be roughly 5MB in size. Now let's read it using Get...
  • Getting Assigned IP Addresses

    You should use this to retrieve all IP addresses assigned to your computer: Get-WMIObject win32_NetworkAdapterConfiguration | Where-Object { $_ . IPEnabled -eq $true } | Foreach-Object { $_ . IPAddress } Get-WMIObject win32_NetworkAdapterConfiguration...
  • Encrypting PowerShell Scripts

    Sometimes, you may want to hide the code of your PowerShell script in order to protect passwords contained within the code. One way to safely encrypt PowerShell script is by converting it into a secure string. You must first create a sample script you...
1 2 3 4 5 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.