Happy 4th of July

By | July 2, 2020

This Powershell code creates the American Flag:
function Write-Color([String[]]$Text, [ConsoleColor[]]$Color = "White", [int]$StartTab = 0, [int] $LinesBefore = 0,[int] $LinesAfter = 0, [string] $LogFile = "", $TimeFormat = "yyyy-MM-dd HH:mm:ss") {
$DefaultColor = $Color[0]
if ($LinesBefore -ne 0) { for ($i = 0; $i -lt $LinesBefore; $i++) { Write-Host "`n" -NoNewline } } # Add empty line before
if ($StartTab -ne 0) { for ($i = 0; $i -lt $StartTab; $i++) { Write-Host "`t" -NoNewLine } } # Add TABS before text
if ($Color.Count -ge $Text.Count) {
for ($i = 0; $i -lt $Text.Length; $i++) { Write-Host $Text[$i] -BackgroundColor $Color[$i] -NoNewLine }
} else {
for ($i = 0; $i -lt $Color.Length ; $i++) { Write-Host $Text[$i] -BackgroundColor $Color[$i] -NoNewLine }
for ($i = $Color.Length; $i -lt $Text.Length; $i++) { Write-Host $Text[$i] -BackgroundColor $DefaultColor -NoNewLine }
}
Write-Host
if ($LinesAfter -ne 0) { for ($i = 0; $i -lt $LinesAfter; $i++) { Write-Host "`n" } } # Add empty line after
if ($LogFile -ne "") {
$TextToFile = ""
for ($i = 0; $i -lt $Text.Length; $i++) {
$TextToFile += $Text[$i]
}
Write-Output "[$([datetime]::Now.ToString($TimeFormat))]$TextToFile" | Out-File $LogFile -Encoding unicode -Append
}
}
Write-Color -Text " * * * * * * ", " " -Color DarkBlue,Red
Write-Color -Text " * * * * * ", " " -Color DarkBlue,White
Write-Color -Text " * * * * * * ", " " -Color DarkBlue,Red
Write-Color -Text " * * * * * ", " " -Color DarkBlue,White
Write-Color -Text " * * * * * * ", " " -Color DarkBlue,Red
Write-Color -Text " * * * * * ", " " -Color DarkBlue,White
Write-Color -Text " * * * * * * ", " " -Color DarkBlue,Red
Write-Color " " -Color White
Write-Color " " -Color Red
Write-Color " " -Color White
Write-Color " " -Color Red
Write-Color " " -Color White
Write-Color " " -Color Red