November 2009 - 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
  • Writing to the Registry

    Adding or changing registry values is not always intuitive with PowerShell. Here is a function called Set-RegistryValue that will make your life easier: function Set-RegistryValue ( $key , $name , $value , $type = "String" ) { if (( Test-Path...
  • Reading Registry Values

    In PowerShell, you will need to use one of the Registry virtual drives to read from the Windows Registry as it is - not always intuitive. Here are two functions to make your life easier. Get-RegistryValues lists all values stored in a registry key: function...
  • Running Commands On Multiple Computers

    You can work remotely not just for single computers. You can also run your commands against multiple computers like this: $computer = Get-Content computers.txt $session = New-PSSession -ComputerName $computer Invoke-Command -Session $session { md hklm...
  • Configuring WSMan Remotely for multiple computers

    When working remotely in a peer-to-peer or cross-domain scenario, you will have to add all the computers you'd like to communicate with into the trusted hosts list. Unfortunately, when you try this, any new entry will overwrite the existing one, so...
  • Remote Configuration in a Peer-to-Peer environment (or across domains)

    By default, PowerShell requires Kerberos authentication to operate remotely, so you cannot use it in a simple peer-to-peer scenario. You can also not use it in a cross-domain scenario with untrusted domains. You will need to allow WSMan to use different...
  • Enabling PowerShell V.2 Remotely

    Setting up the brand new PowerShell v.2 remotely in a domain environment is easy: simply run Set-WSManQuickConfig As long as you have proper privileges to run this command, it does everything automatically: it runs the WinRM service, sets up a PowerShell...
  • Retrieving Error Messages From Your Event Logs

    Event logs record all kinds of stuff. To find the important things, use Get-EventLog and query for the events you are seeking. In PowerShell v.2, Get-Eventlog has a lot of new parameters, such as -computername. With it, you can retrieve events from remote...
  • Use Regular Expression to Validate Input

    PowerShell can use regular expressions to validate user input. All you need is a regular expression that adequately defines the pattern you are seeking. Fortunately, you do not need to create regular expressions from scratch. Simply Google them and then...
  • Add New Properties To Your Objects

    You can use Select-Object to add new properties to an existing object. In PowerShell v.2, Select-Object accepts a wildcard, which in turn adds all existing properties. Why would that be useful? Have a look: Dir | Select-Object * , Age | Foreach-Object...
  • Calculating Time Differences

    Use New-Timespan and submit a date if you'd like to know how long it is until next Christmas. New-Timespan automatically compares this date to the current date (and time) and returns the timespan in a number of different formats from which you can...
  • Analyze Parameter Binding

    You probably know that PowerShell is pretty flexible when it comes to parameters you want to submit to cmdlets and functions. You can name them (putting the parameter name in front of your arguments), you can abbreviate the name (as long as the parameter...
  • Why is my PowerShell console not blue?

    When launching powershell.exe directly, you get a console with black background and only 300 lines of buffer text. When you launch PowerShell from your start menu, you really launch a link, and links can store console custom settings. So this time, your...
  • Don't be surprised by the Help bug

    Get-Help is great for discovering cmdlet and function syntax but sometimes it fails on PowerShell v.2. Take a look at this: Get-Help Enable-PSRemoting Get-Help Disable-PSRemoting When you run both lines in PowerShell v.2, only the first one will retrieve...
  • Making Comment-Based Help Compatible

    In a previous tip, you learned how to add Comment-Based Help information to your own functions so that Get-Help can auto-document the usage. However, once you do this your functions break on PowerShell v.1 because v.1 does not know the block comment feature...
  • Using Comment-Based Help

    PowerShell v.2 allows your functions to seamlessly integrate with the built-in PowerShell Help system. All you need to do is a Comment-Based- Help block into each function: function Test-Me ( $parameter ) { <# .SYNOPSIS A useless function .DESCRIPTION...
1 2 Next >
Copyright 2012 PowerShell.com. All rights reserved.