functions/private/Start-Log.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function Start-Log{
    [CmdletBinding()]
    param(
        [Parameter()]
        [ValidateNotNullOrEmpty()]
        [string] $LogName = "SMBDeployment-$(get-date -Format yyyyMMdd-HHmmssmsms)_$(([guid]::newguid().guid))"
    )
    # recreates the log file and sets the script parameter for use in the write-log function

    $script:Log = "$($script:Root)\Log\$($LogName)"
    if(Test-Path -Path $script:Log){
        $null=remove-item -path $script:Log -force
    }
    $LogDirectory = Split-Path $script:Log
    if((Test-Path -Path $LogDirectory) -eq $false){
        $null = new-item -Path $LogDirectory -ItemType Directory -Force
    }
    $null= new-item -type file -path $script:Log
}