function Initialize-Log { param( [string]$LogDirectory ) $LogFileName = "log_$(Get-Date -Format "yyyy-MM-dd_HHmmss").log" $global:LogFilePath = Join-Path -Path $LogDirectory -ChildPath $LogFileName } function Write-Log { param( [string]$Message, [string]$Severity = "Info" ) $Date = Get-Date -Format "yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK" $Prefix = "[$Date]:`t$($Severity.ToUpper())`t`t" Write-Host -Object $Message "$Prefix$Message" | Out-File -FilePath $global:LogFilePath -Encoding utf8 -Append -Force } function Set-StringLength { [CmdletBinding()] param ( [Parameter(Mandatory)] [string]$InputString, [Parameter(Mandatory)] [int]$TotalLength ) if ($InputString.Length -ge $TotalLength) { return $InputString.Substring(0, $TotalLength) } return $InputString + (" " * ($TotalLength - $InputString.Length)) }