Monthly Archives: February 2018

PowerShell while

PowerShell has a number of looping structures – do; while; for; foreach. This is how the PowerShell while loop works The while statement has the form: while (<condition>){<statement list>} The while loop is probably the simplest of the PowerShell loops. … Continue reading

Posted in Powershell | Leave a comment

Get-Date format

A common question revolves around Get-Date format. In other words how can you format the output of Get-Date.  Standard output is PS> Get-Date 27 February 2018 16:02:13 You can use –DisplayHint to control what’s displayed PS> Get-Date -DisplayHint Date 27 … Continue reading

Posted in Powershell | Leave a comment

Iron Scripter puzzles

We keep innovating around the content of the PowerShell Summit to ensure it remains fresh and relevant to our attendees. This year we’re introducing the Iron Scripter competition. As a run up to the main competition I’ve written a number … Continue reading

Posted in Powershell | Leave a comment

PowerShell Scope

PowerShell Scope has an important impact on the way your code runs. When you run a script or a function in PowerShell it runs it in its own scope. This means that all variables, functions, classes, aliases etc are removed … Continue reading

Posted in Powershell | Leave a comment

Controlled zip

Powershell v5 introduced the Compress- and Expand-Archive cmdlets which enabled you to manage compressed archives. I had a question about how you could control adding files to archives using a CSV file. This is how you do a controlled zip. … Continue reading

Posted in PowerShell v5 | Leave a comment

PowerShell if

The PowerShell if statement enables you to branch your code depending in the results of one or more conditional tests. The tests can be anything you need but must produce a boolean – true/false – result.   Also 0 is treated … Continue reading

Posted in Powershell | Leave a comment

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

Posted in PowerShell v6 | Leave a comment