Monday, September 8, 2014

SharePoint 2013 - Powershell deployment simple log / logging function

Function:

$dp0 =  [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Definition)

Function write-log($date,$EventType,$EventMesage,$functionName,$Filename)
{  
    $dp0 = $(get-location)
    $date = get-date
    $index= "$dp0".LastIndexOf("\")
    $logloc="$dp0".Substring(0,$index)
   
    $EventMesages = $EventMesage -replace ",", "."

     $LogFilePath = "$dp0\ScriptExecLogs.csv"
   # Write-Host $LogFilePath
    $EventMesages = $EventMesage -replace ",", "."
   
    if($EventType -eq $null){
        $EventType="Event type not Specified"
    }
    if($EventMesage -eq $null){
        $EventMessage = "NA"
    }
    if($Filename -eq $null){
        $Filename = "No File Provided"
    }
    if($functionName -eq $null){
        $functionName = "Function name not provided"
    }
   
   
   
    Add-content -Path  $LogFilePath -value  "$date,$EventType,$EventMesages,$functionName,$Filename"
}

Function call:

1.write-log $date "message"  "PowerShell Snapin added successfully"   "GlobalCall" "SiteColumn"


2.catch
        {
             write-log $date "error" $_.Exception.Message ("on"+$_.Name+": field creation") "createContentType" "SiteContentType"
        }

1 comment:

  1. Harrah's Casino & Hotel - Mapyro
    Harrah's Resort Southern California, Funner. Map of Harrah's 오산 출장안마 Resort 전주 출장샵 Southern California. 아산 출장샵 Harrah's casino & 아산 출장마사지 hotel. 1 김해 출장안마 map.

    ReplyDelete