Powershell

Using PowerShell Gallery

The PowerShell Gallery is a public repository for PowerShell scripts and modules. It is entirely managed by cmdlets. Before you can use the...

Nested PowerShell Transcripts

In previous versions of PowerShell, session logging (transcripts) were supported only in the PowerShell console, and there could only be one...

Logging PowerShell Sessions

PowerShell always supported session logging in the PowerShell console. Simply enter Start-Transcript to log all input and output to a text file....

Ad-hoc Debugging in PowerShell ISE

Beginning with PowerShell 5.0, you can break into the debugger any time (in the PowerShell ISE). Simply press CTRL+B to invoke the debugger while a...

Revealing Function Source Code

Many of the PowerShell commands are made out of functions. Here is how you can peek into the source code of any function: (Get-Command...

Finding Useful .NET Types

You may have heard about "type accelerators": they are shortcuts for the long .NET type name: PS> [XML] IsPublic IsSerial Name BaseType...

Automatic Unrolling Can Fail

Beginning with PowerShell 3.0, there is a new feature called "Automatic Unrolling": when you specify a property or method on an array, then the...

New Where-Syntax

In PowerShell 4.0 and better, there is a new alternative to the Where-Object cmdlet: $all = Get-Service $all | Where-Object { $_.Status -eq...

Create New XML Item Programmatically

In a previous tip we explained how you can clone an existing XML item to add a new item. This works only when there are already some items in the...

Remove an Item from an XML Document

Removing items from an XML document is almost trivial: you use XPath to identify the node you want to remove, then remove it. Once you save the XML...

Adding New Nodes to an XML Document

If you need to add new items to an XML document that already contains such items, the easiest way is to search for an existing item, then clone it....

Updating XML Content Using XPath

You can use Select-Xml to select content from an XML file, and then change or update its values. This is very powerful. You just need to get...

Updating XML Content

If you need to make changes to an existing XML document, for example to update inventory data, the easiest way is to load the document into an XML...

Reading XML Content

Reading XML formatted text is easy when you use an XML object for it. With its method Load(), you can read in content from a file path or a URL. In...

Designing XML Documents

Today we start a little mini series about XML. To create sample data to play with, you will first create a well-formed XML. While you can create XML...

Finding Out UTC Time

When you work in a global environment, it sometimes becomes necessary to translate the local time to UTC (Universal Time). The conversion is done by...

Fast String Operations

String concatenation is a frequent thing in scripts but when you use the "+=" operator to append text to a string, this slows down your...

Parse an Exact Date

If you need to parse a date or time information out of raw text, and if the date and time format does not adhere to the standards of your operating...

Faster Array Manipulations

The "+=" operator is pretty convenient and can add new elements to an array. If you need this more than once, for example in a loop, then...

Copy Command History to a Script

Sometimes you may have played around with the interactive PowerShell and suddenly realized that some of the commands you played with were pretty...

Compare Versions

Ever wanted to compare software versions? If you do it like this, the result is off: PS> '3.12.11.100' -gt '11.1.22.91' True...

Cleverly Aborting Endless Loop

In a previous tip you have seen how an endless loop can be used to continuously monitor things - until PowerShell is closed, or a user presses...

Finding Executable Path

Here is a one liner telling you the exact location of the executable of any running process. The example returns the path to the PowerShell...

Doing Things Forever

If you want PowerShell to run forever, for example in order to continuously ping a site, use a simple endless loop: #requires -Version 2...

Getting Basic Networking Information

Beginning with Windows 8.1 and Server 2012 R2, the operating system adds a wealth of new cmdlets for OS management. With these cmdlets, it is almost...

Investigating AD Classes

Active Directory organizes its content in classes like "user" or "computer". Each class has a predefined set of attributes, like...

Use Ctrl+Space in ISE!

The PowerShell ISE opens IntelliSense menus frequenty and helps you write code. Sometimes, however, IntelliSense does not pop up automatically,...

PowerShell Killing Itself

If you schedule a script as a scheduled task, or call it externally, and want to make sure the PowerShell process really ends, here is a brute force...

1 44 45 46 47 48 104