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...
  • 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...
  • 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 TobiasAir1 PS > $env:username Tobias You get a lot more information including your security identifier (SID) by using...
  • Optimizing PowerShell Performance

    PowerShell is loading .NET assemblies. These assemblies can be precompiled using the tool ngen.exe which improves loading times (because the DLLs no longer have to be compiled each time they are loaded). Before you think about optimizing the DLLs PowerShell...
  • 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...
  • 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...
  • 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...
  • 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...
  • Listing All WMI Namespaces

    WMI is organized into namespaces which work similar to subfolders. Here's a line that lists all namespaces you got: PS > Get-WmiObject -Query "Select * from __Namespace" -Namespace Root | Select-O bject -ExpandProperty Name Next, you...
  • Formatting XML Files

    Here's a cool little XML formatting tool. It takes the path to any XML file and allows you to specify an indent. Then, it saves the file as new XML file with the indentation you specified. Here's the code for the function: function Format-Xml...
  • Get .NET Runtime Directory

    Ok, this is more for the developers. To find out where your .NET Runtime folder is, try this line: PS > $path = [ System.Runtime.InteropServices.RuntimeEnvironment ] :: GetRuntimeDirectory () PS > $path C:\Windows\Microsoft.NET\Framework64\v4.0...
  • Communicating Between Multiple PowerShells via UDP

    Assume you want to send some information to another PowerShell session, or you'd like to have one session wait until another is ready. Here are two simple functions that allow you to send and receive text information across PowerShell sessions using...
  • Custom Formatting DateTimes

    In a previous tip we published the list of placeholders to define datetime patterns. You can use the very same placeholders to define your own datetime output formats, too. Check out these examples: PS > Get-Date -format ' d MMM yyyy ' 30 Mar...
  • Parsing Custom DateTime Formats (Part 2)

    In a previous tip we illustrated how you can use ParseExact() to parse custom datetime formats. This only works though if the date and time information does not contain extra characters except whitespace. To parse date and time information that has extra...
1 2 3 4 5 Next > ... Last »
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.