sile007
9/5/2017 - 2:07 PM

Function Write Log File

Function Write Log File

# -------------------------------------------------------------------------------
# Log File
# -------------------------------------------------------------------------------

Function WriteLogFile
{
	
	Param ($Message)
	
	
	$ScriptLogPath = "$PSScriptRoot" # + "\Log\"
	$LogFileName = "Log.txt"
	$path = [System.IO.Path]::Combine($ScriptLogPath, $LogFileName)
	$mode = [System.IO.FileMode]::Append
	$access = [System.IO.FileAccess]::Write
	
	$fs = New-Object IO.FileStream($path, $mode, $access)
	$sw = New-Object System.IO.StreamWriter($fs)
	
	$a = Get-Date
	$Now = $a.ToShortDateString() + " " + $a.ToShortTimeString()
	
	$sw.WriteLine("$Now - $Message")
	$sw.Close()
	$fs.Close()
	
}