$logfile = "C:\admin\LOGS\CW-Monitoring-Install_log_$(get-date -format 'yyyyMMdd_hhmmsstt').txt" function log($string, $color) { if ($Color -eq $null) { $color = "gray" } write-host ($string + ' ' + $(get-date -format 'hhmmsstt')) -foregroundcolor $color ($string + ' ' + $(get-date -format 'hhmmsstt')) | out-file -Filepath $logfile -append }