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. For example: $x = 0 while ($x -lt 5){ Write-Host “`$x is $x” $x++ […]
Archive for February, 2018
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 February 2018 PS> Get-Date -DisplayHint Time 16:03:09 PS> Get-Date -DisplayHint DateTime 27 February 2018 16:03:17 […]
Iron Scripter puzzles
Posted by: richardsiddaway | February 27, 2018 Comments Off on 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 of challenges. The first half of the Iron Scripter puzzles are available. The puzzle is published […]
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 from memory at the end of the script. Here’s an example create a class class […]
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. Start by creating a set of test data. 1..100 | foreach { $file = […]
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 as $false and a positive non-zero is $true. A negative non-zero generates an error. […]
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 would be nice […]
PowerShell for loop
Posted by: richardsiddaway | February 15, 2018 Comments Off on 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++) { $i } In […]
PowerShell v6 and PowerShell Direct
Posted by: richardsiddaway | February 13, 2018 Comments Off on 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 subset of the […]
Putting on the style
Posted by: richardsiddaway | February 4, 2018 Comments Off on 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 taught to code […]
Categories
- .NET
- Active Directory
- Architecture
- Azure
- Bash
- BITS
- Books
- CDXML
- CIM
- Cloud
- COM
- Containers
- Deep Dive
- Desired State Configuration
- DevOps
- DHCP
- DNS
- DSC
- European Summit
- Events
- Exchange
- File System
- Firewall
- General
- General IT Matters
- Hyper-V
- IIS
- Infrastructure
- IT Community
- IT Security
- Learning PowerShell
- Linux
- Math
- Microsoft
- Modules
- Nano Server
- Networking
- Office 2010
- Office 2013
- Open Source
- Opinion
- Outlook
- Philosophy
- PowerShell
- PowerShell 7
- PowerShell and .NET
- PowerShell and Active Directory
- PowerShell and CIM
- PowerShell and Exchange 2007
- PowerShell and IIS
- PowerShell and SQL Server
- PowerShell and WMI
- PowerShell Basics
- PowerShell original
- PowerShell Summit
- PowerShell User Group
- PowerShell User Group 2
- PowerShell v2
- PowerShell V3
- PowerShell v4
- PowerShell v5
- PowerShell v6
- PowerShell.org
- PowerShellGet
- PowerShellV2
- PSAM
- Rant
- Registry
- Scripting
- Scripting Games
- Scripting Games 2104
- Security
- SQL Server
- Storage
- Strings
- Summit
- Technology
- Uncategorized
- Virtualization
- Windows 10
- Windows 2012 R2
- Windows 7
- Windows 8
- Windows 8 Server
- Windows 8.1
- Windows Server
- Windows server 1709
- Windows Server 2008
- Windows Server 2008 R2
- Windows Server 2012
- Windows Server 2012 R2
- Windows Server 2016
- Windows Server 2019
- WMFv5
- WPF
- WSUS