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
  • 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...
  • Filter by More Than One Criteria

    You should probably use Get-Childitem with its -filter parameter to list specific files because it is much faster than -include. This line will locate all log files recursively in your Windows folder structure: Dir $env:windir -Filter * . log -Recurse...
  • Finding Software Updates

    In Windows Vista/Server 2008, Microsoft introduced many new service and application specific log files. PowerShell can access those with Get-WinEvent. Here is how useful the rich information can be in these logs. The function Get-SoftwareUpdates will...
  • Search for Keywords in Help Files

    You may be surprised that you cannot filter Help texts by keywords: Get-Help Dir | Select-String "File" This will not return anything, even though there is a word called “file” in the Help text (at least in English versions of PowerShell...
  • Kill Specific Excel Instances (or other programs)

    Stop-Process can very easily kill all instances of Excel or another program. So this line will kill all instances of Excel: Stop-Process excel – ErrorAction SilentlyContinue You will need the process ID, which you may not have, to kill specific...
« First ... < Previous 72 73 74 75 76 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.