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
  • Load registry user hive

    If you need to manipulate registry data from another user, you may be out of luck because HKEY_CURRENT_USER always points to your own user data. However, you can manually load a user hive like this: reg.exe /load HKU\Testuser c:\users\tom\ntuser.dat PS...
  • Dump enumerations

    You can create a simple helper function called Get-Enum to list all the values in an enumeration: function Get - Enum ( $name ){ [ Enum ] :: GetValues ( $name ) | Select-Object @ { n = "Name" ;e = { $_ }} ,@ { n = "Value" ;e = { $_...
  • Compare services on two computers

    Ever wondered why one computer runs well and another does not? Here is an example of how you can compare service configuration on two machines as long as you have privileges in place to remotely access the other machine: PS > $own = Get-Service PS...
  • Use Foreach-Object instead of Select-Object -expandProperty

    As you may know, Select-Object can return the content of an object property when you use the parameter -expandProperty. This will get you a list of all software manufacturers of all running processes: Get-Process | Select-Object -expandProperty Company...
  • Appending text files without new line

    You can use Out-File with -Append to append lines to a text file, but there is no way to add text information without a line break. To do that, you can use .NET Framework directly. Here is an example: PS > "New Line1" | Out-File $env:temp...
  • Creating random passwords

    Take a look how easy it is for PowerShell to create random passwords: PS > $list = [ Char []] ' abcdefgABCDEFG0123456&%$ ' PS > -join ( 1 . .20 | Foreach-Object { Get-Random $list -count 1 }) CbA3egDcgc55a064D50F PS > -join ( 1 ....
  • Escaping text in regular expressions (RegEx) patterns

    Some PowerShell operators, such as –match, expect regular expressions. If you just want to match plain text, you will need to escape any special regular expressions character in your text. Let RegEx handle it for you rather than doing that manually...
  • Formatting multiple text lines

    Use the awesome formatting operator -f to insert dynamic information into text! You can store the formatting information in a variable and use it in a loop to format multiple lines of text. Here, the format in $format will tell PowerShell to format the...
  • Creating new GUIDs in various formats

    You can easily create new GUIDs (Globally Unique Identifiers) using the GUID type and its NewGUID() method. But did you know that you can use a GUIDs toString() method to create GUIDs in a number of different formats? Have a look: $guid = [ GUID ] ::...
  • Read text files that are in use

    Get-Content can read text files only line-by-line. Use .NET directly if you need the exact content of a text file as one large text. Here is how you read the entire text file in one line: PS > [ System.IO.File ] :: ReadAllText ( "c:\sometextfile...
  • Enumerate Device Services

    You will find that Get-Service will not list device services. Here is how you can enumerate those low-level services: [ System.ServiceProcess.ServiceController ] :: GetDevices () ReTweet this Tip!
  • Find Latest Processes

    You should try this piece of code to find all processes that were started within the past 10 minutes: Get-Process | Where-Object { try { ( New-Timespan $_ . StartTime ) . TotalMinutes -le 10 } catch { $false } } This will only cover processes that you...
  • Check for Wildcards

    If you need to test for wildcards, you should try this .NET method: $path = "c:\test\*" [ Management.Automation.WildcardPattern ] :: ContainsWildcardCharacters ( $path ) ReTweet this Tip!
  • Use Multiple Wildcards

    Did you know that you can use multiple wildcards in paths? This will give you a lot of control. Check this out: This line will find all DLL-files in all sub-folders up to two levels below your Windows folder: Resolve-Path $env:windir \ * \ * \ * . dll...
  • Open Many Files With One Command

    To quickly open all files of a kind, such as all text or script files found in a folder, you should try the Open-File function. It will accept a simple pattern, such as *.txt which opens all text files, or a*.ps1,which opens all PowerShell scripts that...
« First ... < Previous 58 59 60 61 62 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.