ComputerName

If you want to find the name of the local computer you use $env:COMPUTERNAME. Except that doesn’t exist in Linux PowerShell v6 – you have to use $env:HOSTNAME PowerShell 1 Consistency 0 I can live with having $env:HOSTNAME because I bet that’s what Linux users would look for. It...
PowerShell for loop

PowerShell has a number of looping mechanisms – do-while; do-until; foreach; while and for loops. In this post I’ll show you how to use the PowerShell for loop. A for loop iterates a predefined number 0f times. A basic for loop looks like this:
for ($i=0; $i -lt 10; $i++)...
PowerShell v6 and PowerShell Direct

Not seen this reported anywhere so thought I post. PowerShell v6 went to GA in January 2018. PowerShell Direct is a feature of Windows 10/Windows Server 2016. By accident I found that PowerShell v6 and PowerShell Direct work together. PowerShell v6 is based on .NET core which is basically a...
Putting on the style

PowerShell is all about getting things done but how you do things can be as important as what you do. I’ll explain what I mean so you be able to be putting on the style. While PowerShell is used by a number of developers its predominantly an administrators tool. Most administrators aren’t...
Dynamic parameters

PowerShell has always been an extensible language meaning that you can add things on, change things and even remove things if required. One way that this extensibility surfaces is dynamic parameters. A dynamic parameter is a parameter that is available when certain conditions are met. Many of...
CIM_ or Win32_

If you dig into the classes available on a Windows machine you’ll see a mixture of prefixes – namely CIM_ and Win32_ used for the classes. So which should you use CIM_ or Win32_ Lets start by seeing whats available:
PS> Get-CimClass -ClassName *Volume*
NameSpace:...
Clear-RecycleBin

Every so often I find a new cmdlet in PowerShell. This was the case with Clear-RecycleBin that I’ve just found. It appears to have been introduced with PowerShell 5.0 BUT isn’t available in PowerShell 6.0 With pretty simple syntax PS> Get-Command Clear-RecycleBin...
Documentation can be wrong!

We rely on vendor documentation to help us solve problems. Documentation is produced by people and people make mistakes so Documentation can be wrong! As an example: The CIM class Win32_OperatingSystem has a Description property. According to the documentation the Description property...
PowerShell sleep

PowerShell use tends to be very interactive. You run a command at the console and get some results. You run a script and get some results. How do you make PowerShell sleep? There’s a few ways you can make PowerShell code sleep. First there’s Start-Sleep
PS> for ($i=0; $i -le 10;...
PowerShell –f string

A PowerShell –f string is used to format the data inside a string. –f is usually referred to as the format operator. The operation of the format operator is best explained by examples. At its simplest you create fields in the string using {} and the arguments to the right of the –f...