public/write-log.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function write-Log() {
    <#
    .SYNOPSIS
    Name: write-log
    output formater for logging information in azure automation
    powershell runbook
    .DESCRIPTION
    this function format and output following naming convention
    it will output them on the console by default it is meant to be used
    with Azure Powershell Runbook (not worklfow)
    .PARAMETER taskname (OPTIONAL)
    param to specifiy log file name
    .PARAMETER Level (OPTIONAL)
    param to specifiy level of the log (INFO, ERRO, WARN)
    .PARAMETER Message (MANDATORY)
    content of the error (as detailed as possible)
    .EXAMPLE
    write-log -Message "Checking users"
    .EXAMPLE
    write-log -level ERRO -Message "unable to resolve www.example.com"
    .EXAMPLE
    write-log -activity "MailboxMigration" -level WARN -Message "Unable to verify SSL certificate validity"
    #>

        Param (
            [Parameter(Mandatory = $false)]  [string]$activity,
            [Parameter(Mandatory = $false)]  [string]$level = "INFO",
            [Parameter(Mandatory = $true)]   [string]$Message
        )            
        if (!($activity)) {
            $activity = "task"
        }
        $Line = "$activity : $Level - $Message"
        write-output $Line 
    }