So working with a customer on a bunch of scripts to manipulate SharePoint and we needed a standard method of logging what we were doing in our scripts. So I decided to write a few functions that would make our life easier and would create uniformity in how things are logged.
So the first function I wrote simply creates a new logfile, and I wrote it so that if you wanted to all you would have to do is call the function, this means that both parameters have default values and of course it will return the full path and name of your log file. I did several things to make this work nicely
param([String]$LogPath = "C:\Script", [string]$PreFix = "ScriptOutput")
$d = Get-Date
$Day = $d.Day
$Month = $d.Month
$Year = $d.Year
$Hour = $d.Hour
$Min = $d.Minute
$Sec = $d.Second
if(!(Test-Path -Path $LogPath -PathType Container))
New-Item -Path $LogPath -ItemType Directory | Out-Null
$FileName = New-Item -Path "$LogPath\$PreFix$Day$Month$Year$Hour$Min$Sec.log" -ItemType File -Force
If you would like to check out the function you can download it from here
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.