May 2012 - Power Tips

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
  • Adding Clock to PowerShell Console

    Maybe you'd like to include dynamic information such as the current time into the title bar of your PowerShell console. You could update the console title bar inside your prompt function, but then the title bar would only get updated each time you...
  • Integrating WhoAmI Into PowerShell

    There is a cool little tool called whoami.exe which is part of Windows ever since Windows Vista. Since it can provide results not just in plain text but also as comma separated values, it is very easy to integrate into PowerShell. For example, to find...
  • Copying Large Files with BITS

    You can use Copy-Item or the console applications xcopy and robocopy to copy large files. But did you know that you can also use the BITS service to do this? The BITS service is supposed to download large update files and does so in a very robust way...
  • Executing Commands in Groups

    In traditional batch files, you can use "&&" to execute a second command only if the first one worked. In PowerShell, the same can be achieved by using the try/catch construct. You just need to know some little tricks. Take a look at...
  • Get Localized Month Names

    To get a list of month names, you could use this line: PS > [ System.Enum ] :: GetNames ([ System.DayOfWeek ]) Sunday Monday Tuesday Wednesday Thursday Friday Saturday However, this returns a culture-neutral list which is not returning the month names...
  • Clearing WinEvent Logs

    With Get-WinEvent you can access the various Windows log files such as this one: PS > Get-WinEvent Microsoft - Windows - WinRM / Operational There is no cmdlet to actually clear such event log, though. With this line, you can: PS > [ System.Diagnostics...
  • Extract Paths from Strings Like Environment Variables

    If you'd like to add a path to the %PATH% environment variable, that's easy: PS > $env:path += ' ;c:\newpath ' But how would you remove a path? Here's a clever way: PS > (( $env:path -split ' ; ' ) -ne ' C:\Windows...
  • Matching "Stars"

    Asterisk serve as wildcards, so how would you check for the presence of an asterisk? It's much harder than you might think: PS > ' Test* ' -eq ' * ' False PS > ' Test* ' -like ' ** ' False PS > ' Test '...
  • Finding Domain Controllers

    If your computer is logged on to an Active Directory, here is some code to get to your domain controllers. Note that this will raise errors if you are currently not logged on to a domain. PS > $Domain = [ System.DirectoryServices.ActiveDirectory.Domain...
  • Creating Symmetric Array

    By default, PowerShell uses jagged arrays. To create conventional symmetric arrays, here's how: PS > $array = New-Object ' Int32[,] ' 2 , 2 This creates a two-dimensional array of Int32 numbers. Note that each dimension starts with 0, so...
  • Who am I?

    If you'd like to know your current user account, of course you can query environment variables like this: PS > $env:userdomain PS > $env:username You get a lot more information including your security identifier (SID) by using the appropriate...
  • Getting Group Memberships

    If you'd like to know in which groups you are member, here's a simple piece of code that returns the list of groups you belong to: PS > $User = [ System.Security.Principal.WindowsIdentity ] :: GetCurrent () PS > $User . Groups | ForEach...
  • Map Network Drive

    Sure you can use the command net use to map a network drive. But this would not check for existing mapped drives. Here's a small function that first checks to see that the URL you are mapping to does not yet exist, avoiding duplicate mapped drives...
  • Comparing Services in PowerShell

    Compare-Object is one of the most widely ignored most powerful cmdlet around. It can compare results and figure out differences. For example, if you'd like to know the differences in service configuration between two machines, here's the simple...
  • Parsing Date and Time

    Parsing a date and/or time information is tricky because formatting depends on the regional settings. This is why PowerShell can convert date and time based on your regional settings or in a culture-neutral format. Let's assume this date: PS >...
1 2 Next >
Copyright 2012 PowerShell.com. All rights reserved.