Automation

PowerCli/ Powershell  Logger

powerclilogo

Instead of using “Write-Host” to write the output to your current Powershell or PowerCli session, try making use of a logger.
Using it is very simple. Replace “Write-Host” with “LogInfo” and all those events will be written to a log file.0


function ConfigureLogger()
{
     if((Test-Path Log) -eq $false)
     {
           $LogFolderCreationObj=New-Item -Name Log -type directory
     }
     $date= Get-Date -UFormat "%Y-%m-%d %H-%M-%S" 
     $Script:logFile="$date.log"
}
ConfigureLogger	

function LogInfo($message) 
{$date= Get-Date 
$outContent = "[$date] ---- $message"
Add-Content ".\log\$Script:logFile" $outContent 
} 

 


 

Share on Facebook0Tweet about this on TwitterShare on LinkedIn0Share on Google+0