Logging Function for Scripts


Hi All,

We often log the errors/information warning while running the scripts in PowerShell. If we have the function , then it is better to call them where ever we need it in script instead of repeatedly adding the logging code.

## function for writelogs

function WriteLogs($LogMessage, $LogType)

{

$LoggingDateTime=get-date;

write-host

"$LogType, ["+
$LoggingDateTime
+
"]:"+ $LogMessage | Add-Content -Path $LogFilepath

}

You can call this function like below

WriteLogs "***Installation failed: *** " "Error"

Regards,

Chaitanya

Leave a comment

Design a site like this with WordPress.com
Get started