-
-
Save irwins/30025a84c1af72d8c576c3d73db95e7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Class WriteLog{ | |
[string]$FileBaseName = 'Temp' | |
[string]$LogDirectory = 'C:\Scripts\export' | |
[string]$Preference = 'SilentContinue' | |
[bool]$Console = $true | |
[PSObject[]]$InfoMessages | |
#default constructor | |
WriteLog(){} | |
#constructor | |
WriteLog($fbn,$ld){ | |
$this.FileBaseName = $fbn | |
$this.LogDirectory = $ld | |
} | |
WriteInformation($MessageData){ | |
$info = $false | |
if ($this.Preference -eq 'Continue') { $Info = $true } | |
if ($Info) { | |
$this.InfoMessages += Write-Information -MessageData $MessageData 6>&1 | Select-Object * | |
} | |
if($this.Console){ | |
Write-Information -MessageData $MessageData -InformationAction Continue | |
} | |
} | |
ExportToText(){ | |
$this.InfoMessages | | |
Select TimeGenerated,MessageData | | |
Out-File "$($this.LogDirectory)\$($this.FileBaseName).txt" -Encoding utf8 -Force -Append -Width 1000 | |
} | |
ExportToXML(){ | |
$this.InfoMessages | | |
Export-Clixml -Path "$($this.LogDirectory)\$($this.FileBaseName).xml" -Encoding UTF8 -Force | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment