New-LogFile.ps1
<#
.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]$logFileName, [Parameter(Mandatory = $true)] [string]$logFolderPath ) [string]$logFileSuffix=".log" [string]$fileName=$logFileName+$logFileSuffix # Get our log file path $logFolderPath = $logFolderPath+"\"+$logFileName+"\" $global:xmlPath = $logFolderPath #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 $_ } } } |