Powershell – More Code Snippits

Getting the Date:

$now = Get-Date

I like this format for File names:

$Cdate = get-date -f “yyyy-MM-dd-HH-mm-ss”

How to log to a file:

#
Log to file
#
$STR_Error = $null
$NOW = Get-Date -Format s
$STR_Error = $NOW + “, ” + $STR_AffectedGroupName + “, FAILED, AD Group not found.,” + $STR_ADGETERROR
Echo $STR_Error | Out-File $log -Append
$STR_Error = $null