A common task when working with the command prompt is to write the output of commands to a file....
Author Archive for: Wolfgang Sommergut
4sysops - The online community for SysAdmins and DevOps
Copy-Item, Move-Item – Copy and move files with PowerShell

PowerShell offers a whole collection of file management cmdlets. To copy and move files, you can use Copy-Item and...
Where-Object – Filter data with PowerShell

Cmdlets usually return a large collection of objects, but often you only need a few of them. In these...
Strings in PowerShell – Replace, compare, concatenate, split, substring

The processing of strings is one of the most common operations in scripting languages. Traditional tools such as batch...
Rename-Computer – Remotely rename computers with PowerShell

In the past, if you wanted to rename remote computers on the command line or with scripts, WMI or...
Random numbers, temporary file names, and GUIDs in PowerShell

In scripts, you sometimes need random values for numbers, names of temporary files, or GUIDs for unique registry and...
PowerShell Select-Object – Filter object properties

With PowerShell’s abundant cmdlets, you can retrieve almost any type of system information. However, you often receive more data...
The regular expression (RegEx) in PowerShell

The support of regular expressions is a must-have feature for every modern scripting language. PowerShell offers various language constructs...
PowerShell Select-String – Search in files

Windows comes with the two command-line tools find and findstr that allow you to search in text files. The...
The PowerShell function – Parameters, data types, return values

Functions in PowerShell allow you to combine multiple statements and improve the reusability of your code. In this post,...
How to get the PowerShell version

To ensure that your PowerShell code runs on every PC, you have to get the PowerShell version in your...
How to (remotely) read the MAC address

The Media Access Control (MAC) address is the worldwide unique ID of a network adapter. You need the MAC...
setx – Store file contents or Registry values in environment variables

setx is a Windows command-line tool with useful parsing features that allows you to read data from files and...
msinfo32, wmic – Remotely read system information with WMI

Windows comes with two utilities that allow you to read system information for remote computers through Windows Management Instrumentation...
grep for Windows – findstr

findstr is a grep replacement for Windows that supports the most important functions of the popular UNIX search tool...
PowerShell loops: For, Foreach, While, Do-Until, Continue, Break

Like most procedural programming languages, PowerShell supports a variety of loops. A specialty of Microsoft’s scripting language is that...
Arrays in PowerShell – Create, change, read, sort, delete

Like any other scripting language, PowerShell supports the array data type. Its purpose is to combine values in a...
Send email with PowerShell

As of version 2.0, PowerShell comes with a cmdlet that allows you to send emails. It is relatively simple...
IF, ELSE, SWITCH: Conditional statements in PowerShell

All procedural programming languages require constructs that allow them to execute instructions that are dependent on certain conditions. Like...
PowerShell comparison operators -eq, -lt, -gt, -contains, -like, -match

For conditional statements or loops, you have to compare values to control the progress of the script. Like all...