forked from timmcmic/DLConversionV2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
New-LogFile.ps1
78 lines (52 loc) · 2.09 KB
/
New-LogFile.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<#
.SYNOPSIS
This function tests for and creates the log file / log file path for the script.
.DESCRIPTION
This function tests for and creates the log file / log file path for the script.
.PARAMETER logFolderPath
The path of the log file.
.PARAMETER groupSMTPAddress
The SMTP address of the group being migrated - this will be parsed for the log file name.
.OUTPUTS
Ensure the directory exists.
Establishes the logfile path/name for subsequent function calls.
.EXAMPLE
new-logfile -groupSMTPAddress ADDRESS -logFolderPath LOGFOLDERPATH
#>
Function new-LogFile
{
[cmdletbinding()]
Param
(
[Parameter(Mandatory = $true)]
[string]$groupSMTPAddress,
[Parameter(Mandatory = $true)]
[string]$logFolderPath
)
#Define the string separator and then separate the string.
[string]$separator="@"
[array]$fileNameSplit = $groupSMTPAddress.Split($separator)
#First entry in split array is the prefix of the group - use that for log file name.
[string]$fileName=$fileNameSplit[0]+".log"
# Get our log file path
$logFolderPath = $logFolderPath+$global:staticFolderName
#Since $logFile is defined in the calling function - this sets the log file name for the entire script
$global:LogFile = Join-path $logFolderPath $fileName
#Test the path to see if this exists if not create.
[boolean]$pathExists = Test-Path -Path $logFolderPath
if ($pathExists -eq $false)
{
try
{
#Path did not exist - Creating
New-Item -Path $logFolderPath -Type Directory
}
catch
{
throw $_
}
}
out-logfile -string "================================================================================"
out-logfile -string "START LOG FILE"
out-logfile -string "================================================================================"
}