Category Archives: Powershell Basics

Get-Date -UFormat

The Get-Date  -UFormat parameter formats the date using Unix format.  The full list of format specifiers are in the Notes section of the Get-Date help file. Some examples are: PS> Get-Date -UFormat ‘%Y-%m-%d %H:%M%:%S%Z’ 2019-05-27 20:40:11+01 4 digit year – … Continue reading

Posted in Powershell Basics | Leave a comment

Get-Date –Format

Get-Date –Format enables you to control the formatting of the datetime object returned by the cmdlet. A standard call to get date returns: PS> Get-Date 27 May 2019 12:36:47 The –Format parameter takes a value from the DateTimeFormatInfo class – … Continue reading

Posted in Powershell Basics | Leave a comment

Exclusive OR

PowerShell has a number of logical operators – –  -and, –or, –not (or !). One I’ve really thought about is the exclusive OR operator –xor. With a standard –or operator the result is TRUE if one of the statements is … Continue reading

Posted in Powershell Basics | 1 Comment

Useful constants

PowerShell provides easy access to some useful constants. I often see people calculating these values rather than using the constants. PowerShell recognises kb, mb, gb, tb and pb for kilobyte, megabyte, gigabyte, terabyte and petabyte respectively. You can use them … Continue reading

Posted in Powershell Basics | Leave a comment

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

Posted in Powershell Basics | Leave a comment

PowerShell file extensions

There are a number of file extensions associated with PowerShell. If you’re not aware of them they may cause you problems. You’ll commonly find these PowerShell file extensions: .ps1 – a PowerShell script. May contain functionality such as functions or … Continue reading

Posted in Powershell Basics | Leave a comment

PowerShell pause

PowerShell pause – how can you pause a PowerShell script? Two ways come to mind. First if you just want the script to pause for a specified time period then you can use Start-Sleep 1..10 | foreach {   $PSItem   if … Continue reading

Posted in Powershell Basics | 3 Comments