December 2010 - 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
  • Comparing Services

    Compare-Object can help when troubleshooting computers. For example, you should try this to compare the service status on two machines and find out where services are configured differently: $machine1 = Get-Service -ComputerName server1-or -IP1 $machine2...
  • Checking Whether User or Group Exists

    To find out whether a given local or domain user/group exists, you can simply use the static method Exists(): [ ADSI ]:: Exists ( 'WinNT://./Tobias1' ) This will check whether there is a local account named "Tobias1." To check domain...
  • Reading Text Files as One Chunk

    In a previous tip, you learned how to quickly read in text files. The result was a string array. If you want to read the text as one large string ultrafast, you can use this approach: [ System.IO.File ]:: ReadAllText ( "c:\somefile.txt" ) ReTweet...
  • 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...
  • Making Your Keyboard Sound like Typewriter

    PowerShell is all about typing. But if you'd like to get back the old-fashioned typewriter sound, here is a freeware tool that can bring it back: http://www.grc.com/freeware/clickey.htm ReTweet this Tip!
  • Disabling Automatic Page Files

    If you would like to programmatically control page file settings, you can use WMI but must enable all privileges using -EnableAllPrivileges. The code below will disable automatic page files: $c = Get-WmiObject Win32_ComputerSystem -EnableAllPrivileges...
  • Eliminating Duplicate Words

    Let's assume you want to eliminate duplicate words in a text. Here is how you can do this: 'this text text contains duplicate words words following each other' -replace '\b(\w+) ` (\s+\1){1,}\b' , '$1' ReTweet this Tip!
  • Add Whitespace after Commas

    Operator replace is extremely powerful when you use back references. For example, to make sure in a text that there is a space after each comma, you can try this: 'After each comma,I want a whitespace,but only if there was no whitespace in the first...
  • Use Back References with -Replace

    If you need to replace text with some other text and keep a reference to the original text, you can use the backreferenceback reference placeholder $0: 'The problem was described in KB123456. Look it up.' - replace 'KB\d{6}' , 'KB99999...
  • Adding Quotes in Quotes

    If you need quotes to appear inside a quoted string, you should use quotes: $text = "Hello ""World""" $text = 'Hello ''World''' ReTweet this Tip!
  • Running Native Commands in PowerShell

    Sometimes it only takes a little tweaking to make a native command run well inside PowerShell. For example, this line runs in cmd.exe but fails in PowerShell: find "dir" * . ps1 As it turns out, the command requires the quotes, and PowerShell...
  • Create Complex Random Passwords

    Here is how you can create random passwords that meet certain requirements: function Get-RandomPassword { param ( $length = 10, $characters = 'abcdefghkmnprstuvwxyzABCDEFGHKLMNPRSTUVWXYZ123456789!"§$%&/()=?*+#_' ) # select random...
  • Create Random Passwords

    Whenever you need to create a new random password, be sure to check out this function: function Get-RandomPassword { param ( $length = 10, $characters = 'abcdefghkmnprstuvwxyzABCDEFGHKLMNPRSTUVWXYZ123456789!"§$%&/()=?*+#_' ) # select...
  • Using MsgBox Dialogs

    Have you ever used VBScript? Would you like your MsgBox dialog back? Here is how: [ System.Reflection.Assembly ]:: LoadWithPartialName ( 'Microsoft.VisualBasic' ) | Out-Null $rv = [ Microsoft.VisualBasic.Interaction ]:: MsgBox ( 'Do you want...
  • Creating Shortcuts on your Desktop

    PowerShell and .NET can do amazing things, but they are not good at creating shortcuts. However, you can create a shortcut on your Desktop in a matter of only a few lines by using COM objects instead: $shell = New-Object -ComObject WScript.Shell $desktop...
1 2 Next >
Copyright 2012 PowerShell.com. All rights reserved.