How to format a DateTime in PowerShell

The same as you would in .NET:

$DateStr = $Date.ToString("yyyyMMdd")

Or:

$DateStr="{0:yyyyMMdd}" -f $Date

Leave a Comment