Tags

, ,

Here is a way to get prette nice logging with Powershell. I’m still working on it, and there will come an update later…

The “Logwrite” function takes 3 parameters. The first one is the $ts, it print the date into the logfile.

The second is a string you can use to make the logfile more readable, and finally the third parameter prints a vaiable value into the logfile.

Output example:

2013.02.18-16.11.30 package information
2013.02.18-16.11.30 PackageName: Adobe Adobe Reader 9.3 ALL_ENUS_R1
2013.02.18-16.11.30 Accepted exitcode: 2;3010
2013.02.18-16.11.30 Install is startet
2013.02.18-16.11.30 script/file executed AdobeReader.vbs
2013.02.18-16.11.30 Install has ended

 

 

Script example:

$LogFile=“C:\temp\PSWRAP.txt”

[xml]$Xmlfile=Get-Content “<path to XML file>\test.xml”

Packageinfo

Install

Function LogWrite([string]$line=“*”,$val) {

$ts=Get-Date–formatyyyy.MM.ddHH.mm.ss 

Add-Content$logFile“$ts $line $val”

}

Function Packageinfo {

Logwrite “package information”

$packagename =$xmlfile.Package.Name

Logwrite “PackageName:”$packagename

$Exitcodes =$Xmlfile.Package.Install.AllowedReturncodes

Logwrite “Accepted exitcode:”$Exitcodes

}

 

Function Install {

LogWrite “Install is startet”

$Do = $XmlFile.Package.Install.file

Logwrite “script/file executed: “$Do

LogWrite  “Install has ended”

}

Advertisements