-
Notifications
You must be signed in to change notification settings - Fork 29
/
Write-Info.ps1
41 lines (39 loc) · 1.32 KB
/
Write-Info.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
<#
.SYNOPSIS
Writes to the information stream, with color support and more.
.FUNCTIONALITY
PowerShell
#>
#Requires -Version 5.1
[CmdletBinding()] Param(
# Message to write to the information stream.
[Parameter(Position=0,Mandatory=$true,ValueFromPipeline=$true)] $Message,
# Specifies the text color. There is no default.
[Alias('fg')][Nullable[ConsoleColor]] $ForegroundColor,
# Specifies the background color. There is no default.
[Alias('bg')][Nullable[ConsoleColor]] $BackgroundColor,
# Specifies a log file to write the information string to.
[string] $LogFile,
<#
The string representations of the input objects are concatenated to form the output.
No spaces or newlines are inserted between the output strings.
No newline is added after the last output string.
#>
[switch] $NoNewLine,
<#
By default, uses -InformationAction Continue.
This uses the standard $InformationPreference instead.
#>
[switch] $UseInformationPreference
)
Process
{
if($LogFile) {Add-Content -Path $LogFile -Value $Message -Encoding utf8}
if(!$UseInformationPreference) {$Local:InformationPreference = 'Continue'}
Write-Information ([Management.Automation.HostInformationMessage]@{
Message = $Message
ForegroundColor = $ForegroundColor
BackgroundColor = $BackgroundColor
NoNewLine = $NoNewLine
})
}