Windows PowerShell Tip of the Week

Archive

Helpful tips for working with Windows PowerShell. This week’s tip: Three Things You Might Not Know About Windows PowerShell Functions.


Arrays and Hash Tables

Accessing Values in an Array

Accessing specific values – and ranges of values – within an array.

Even More Things You Can Do With Arrays

Tips and tricks for creating new arrays (including empty arrays and strongly-typed arrays) in Windows PowerShell.

Finding Values in an Array

How can you tell if a given value exists in a Windows PowerShell array? Here’s how.

Removing Items From Arrays

Who said you can’t remove an item from an array? You just need to use the right type of array.

Working with Hash Tables

Store key-value pairs, add and remove items, and sort on key or value.


Dates and Times

Formatting Dates and Times

Modifying the display of date-time values.

Formatting Numbers and Dates Using the CultureInfo Object

Format numbers and dates to a specific culture setting, no matter what the current machine settings are.

More Fun with Dates (and Times)

How to use the Get-Date cmdlet to retrieve many different elements of dates and times. Plus, a bonus script that looks at using the .NET Framework to retrieve date and time information.


Formatting Output

Byte Conversion

Converting bytes to megabytes to gigabytes, etc.

Creating Custom Tables

Creating custom tables using the Format-Table cmdlet.

Creating Formatted HTML Output

Find out how useful the ConvertTo-HTML cmdlet can really be.

Formatting Numbers

Displaying numbers in a more-readable format.

Formatting Numbers and Dates Using the CultureInfo Object

Format numbers and dates to a specific culture setting, no matter what the current machine settings are.


Running Windows PowerShell Scripts

Running Scripts Against Multiple Computers

Use command-line arguments, text files, and even a prompt to read in computer names and run a script against each computer.

Running Scripts Against Multiple Computers: Part 2

Running scripts against all the computers in a domain; all the computers in an OU; or all the computers listed in an Excel spreadsheet.


System Administration Tasks

Cool Things You Can Do With the Get-ChildItem Cmdlet

Retrieve hidden files; retrieve files from multiple folders; and much, much more.

Determining the Size of a Folder

A simple task that turns out not to be so simple, then turns out to be simple again.

Finding All the Empty Folders in a Directory Tree

This tip shows you how to – well, how to find all the empty folders in a directory tree.

Getting Information About the Logged-On User

Get information about the logged-on user and the local computer, the easy way.

Listing the TrueType Fonts Installed On Your Computer

Here’s the real “PowerShell” way to get all the TrueType fonts on the computer, and list them in an Internet Explorer window.

Modifying a Read-Write Property Using Get-WMIObject

Don’t let them kid you: you really can modify a read-write property using Get-WMIObject.

Using Test-Path to Verify the Existence of an Object

Find out if files, folders, variables, etc. exist by using the Test-Path cmdlet.

Working with Security Descriptors

Setting security descriptors gets a lot easier when you use the .NET Framework.

Working with SIDs

Find the Security Identifiers (SIDs) for local and Active Directory users; or, conversely, find the user associated with a SID.


The Windows PowerShell Environment

Automatic Script Writing with Get-History

Tired of writing your own PowerShell scripts? Then ask the Get-History cmdlet to write those scripts for you.

Making Progress

Want to know how much longer your script will be running? Try displaying a progress bar.

Modifying Message Colors

Change the background and foreground color of messages (warning, error, etc.).

Taking Things (Like File Paths) Literally

Need to work with filenames and paths with odd charactesr in them? Not a problem in Windows PowerShell.


User Input

Selecting Items From a List Box

Create a form that displays a list box from which users can select.

Multi-Select List Boxes – And More!

You know how to create a list box (or at least you do if you read the tip directly above this one), now find out how to fancy it up a bit by making it multi-selectable and even a little colorful.

Adding a Simple Menu to a Windows PowerShell Script

Display options to the user and take actions based on the option chosen.

Creating a Custom Input Box

An introduction to creating graphical user interfaces with Windows PowerShell.

Creating a Graphical Date Picker

Learn how to display a date control that allows the user to choose a date.

Pausing a Script Until the User Presses a Key

Display the “Press and key to continue…” message and wait.


Windows PowerShell Scripting

Creating and Modifying Environment Variables

Create and modify process-level, user-level, and machine-level environment variables.

Displaying a Message in the Notification Area

Display an icon and a message, and even change the message, in the Windows Notification area.

Filtering Collections With Regular Expressions

Data retrieval for those times when the wildcard character just isn’t enough.

Getting Rid of a COM Object (Once and For All)

Sometimes COM objects stick around a little longer than we’d like. Find out how to get rid of them for good.

The String’s the Thing

An entire tip devoted to strings. Compare two strings, change casing, read parts of strings – even turn a string into an array.

Three Things You Might Not Know About Windows PowerShell Functions

Default values, piping, scope…all that plus some bonus information, all things you should know about working with functions in Windows PowerShell.

Using Calculated Properties

No kilobytes? No problem. At least not when using calculated properties?

Using the Range Operator in Wildcard Queries

Using PowerShell’s range operator in conjunction with cmdlets such as Get-ChildItem.

Using the Switch Statement

Learn about one of the coolest things about Windows PowerShell – the switch statement.

Working with Custom Objects

Create – and use – custom objects within your PowerShell scripts.


Working with Text Files

Calculating Text File Statistics

Determine the number of words, lines, and characters in a text file.

Reading Text Files

Don’t feel bad: everyone you know still uses text files, too.


Working with Variables

Referencing Variables and Variable Values

Embedding variables directly in your strings.

Using Windows PowerShell “Here-Strings”

Assigning multi-line string values to a variable.

Top of pageTop of page