Monthly Archives: June 2018

PowerShell if not

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 … Continue reading

Posted in Powershell | Leave a comment

PowerShell sleep

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 <int> [<CommonParameters>] You can … Continue reading

Posted in Powershell | Leave a comment

PowerShell string concatenation

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 … Continue reading

Posted in Powershell | Leave a comment

Write-Host

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 … Continue reading

Posted in Powershell | 1 Comment

Hyper-V switches

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

Posted in Hyper-V, Powershell | Leave a comment

PowerShell versions

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 … Continue reading

Posted in Powershell | Leave a comment

PowerShell v6.1 preview 3

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 though if you read the release notes there’s a lot of work going on in the … Continue reading

Posted in PowerShell v6 | Leave a comment