PowerShell for Windows Admins:

June, 2018


June 30, 2018  2:05 PM

PowerShell if not

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

When you’re using an if statement you’re usually testing for a positive so how do you do a PowerShell if not There a few scenarios to cover. The simplest is if you’re testing a boolean: PS> $x = $true if ($x) {'Yes'} else {'No'} Yes In an if statement the test ($x) is...

June 30, 2018  1:23 PM

PowerShell sleep

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

Getting PowerShell to sleep or pause during execution can sometimes be useful. This is how you can do a PowerShell sleep. The starting point is Start-Sleep PS> Get-Command Start-Sleep -Syntax Start-Sleep [-Seconds] <int> [<CommonParameters>] Start-Sleep -Milliseconds...


June 30, 2018  1:52 AM

PowerShell string concatenation

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

PowerShell string concatenation is performed using the concatenation operator which is + PS> $a = '1234' PS> $b = '5678' PS> $c = $a + $b PS> $c 12345678 When you concatenate 2 strings you’re creating a new string not adding extra characters to the end of the first...


June 29, 2018  1:37 PM

Write-Host

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

Write-Host has had a bad press over the years culminating in the infamous saying “if you use Write-Host a puppy will die” or words to that effect. So what’s the fuss about? Let’s take some code Write-Host -Object "starting" function t1 { Write-Host -Object "In the...


June 29, 2018  3:56 AM

Hyper-V switches

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

I need to do some work on the Hyper-V switches in my lab so need to see which VMs are on which switch. Easier than I thought: Get-VM | Get-VMNetworkAdapter | select VMname, Name, Switchname


June 29, 2018  3:41 AM

PowerShell versions

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

PowerShell has gone through a number of versions since it was first released in November 2006. These are the major features of the PowerShell versions: PowerShell v1 – initial release with 137 cmdlets. (released with Windows Vista / Server 2008 – not Server Core). Only way to work...


June 28, 2018  7:22 AM

PowerShell v6.1 preview 3

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

PowerShell v6.1 preview 3 became available a couple of weeks ago. https://github.com/PowerShell/PowerShell/releases To the user its a minor set of fixes from preview 2...


June 25, 2018  7:58 AM

PowerShell commands

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

When you think of PowerShell commands most people think of cmdlets but that’s not the full story. PowerShell commands encompass: Aliases Functions Cmdlets Native Windows commands When you type a command name the command types listed above are checked in order to determine the...


June 24, 2018  7:32 AM

Creating collections for output

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

There are many times when you end up creating a collection – either for output or use for performing further processing. There’s a common pattern that’s used when creating collections for output that’s very inefficient. That pattern is: $data = @() 97..122 | foreach { $props =...


June 21, 2018  10:19 AM

Creating objects

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

In my recent post about avoiding Add-Member I showed how to create objects. As with most things in PowerShell there are a number of different ways of creating objects. I showed this code: $os = Get-CimInstance -ClassName Win32_OperatingSystem $comp = Get-CimInstance -ClassName...


Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: