April 2012 - 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 Windows Product Key

    Ever wanted to read out the Windows license key? In the Windows Registry, this key is present, but it is stored as a digital ID. To convert it back to the license key used to originally license the product, try this function. It uses some serious math...
  • Sending Email to Multiple Recipients

    Send-MailMessage can send emails to multiple recipients. You just need to make sure the list of recipients is provided as an array. When you call Send-MailMessage via command line, that's a no-brainer. Simply use a comma-separated list: PS > Send...
  • 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...
  • Adding Progress to Long-Running Cmdlets

    Sometimes cmdlets take some time, and unless they emit data, the user gets no feedback. Here are three examples for calls that take a long time without providing user feedback: $hotfix = Get-Hotfix $products = Get-WmiObject Win32_Product $scripts = Get...
  • Creating Scheduled Tasks From XML

    In a previous tip, we showed how you can export a scheduled task to an XML file. Now, it's time to see how you can re-import that XML file to re-create the scheduled task. Before you can use this tip, you need an XML definition for a task. Check out...
  • Home-Made Driver Query Tool

    Some months ago we introduced to you the driverquery.exe tool and how to convert its output to PowerShell objects. Here's now an amazing function that turns this command-line tool into a graphical tool that lists drivers from both local and remote...
  • Counting Log Activity

    Did you know that Group-Object can analyze text-based log files for you? Here's sample code that tells you how many log entries on a given day a log file contains: Get-Content $env:windir\windowsupdate.log | Group-Object { $_ . SubString ( 0 , 10...
  • Mapping Printers Part 2

    In a previous tip we explained how you can install and map printers remotely using a low level command: rundll32 printui.dll , PrintUIEntry /in /n "\\pntsrv1\HP552" This will map the printer share and also install drivers if required. A dialog...
  • Listing Processes and Process Ownership

    Get-Process can list processes but does not provide information about who is running the process. Here, WMI can help. Get-ProcessEx is a clever function that returns process information including ownership, and it works remotely, too. So if you wanted...
  • Using "Elevator Music" In Your Scripts

    Maybe you'd like to give some feedback to the users of your script while it processes a long-running task. One of the easiest (and most annoying) types of feedback is to play some "elevator music". Here's how: function Start-ElevatorMusic...
  • Killing Long-Running Scripts

    You can use a background thread to monitor how long a script is running, and then kill that script if it takes too long. You can even write to an event log or send off a mail before the script is killed. Here's how you implement such a time bomb:...
  • Output Scheduled Tasks to XML

    Here's an easy way how you can export and dump a task that you created in "Scheduled Tasks" to XML: function Export-ScheduledTask { param ( [ Parameter ( Mandatory = $true )] $TaskName , [ Parameter ( Mandatory = $true )] $XMLFileName )...
  • Checking Text Ending with Wildcards

    In a previous tip you learned how to use the string method EndsWith() to check whether a text ends with certain characters. This method does not accept wildcards, though. So to check text endings for patterns, try this approach instead: PS > "Account123"...
  • Converting Bitmaps to Icons

    If you need a new icon and have no icon editor at hand, then you can take a bitmap file (create one with MS Paint if you must) and have PowerShell convert it into an icon file. The function code also illustrates how you can open an Explorer window and...
  • Checking if a Text Ends with Certain Characters

    You can always use the String method EndsWith(). Just make sure you convert the text to lower-case first to avoid case-sensitive comparison. This will check whether the file name ends with '.pdf': PS > "somefile.PdF" . toLower ()...
1 2 Next >
Copyright 2012 PowerShell.com. All rights reserved.