我目前正在使用 PS ISE 中的颜色。这是一些提示,其中一些只需要阅读,一些需要用户输入。我意识到在使用颜色执行清除和初始化新的写入主机命令后,颜色似乎是自己做的。
我已经提供了测试代码。
有什么想法吗?
function logo {
Write-Host ("==" * 23) -ForegroundColor Red -BackgroundColor DarkRed
Write-Host ("=") -ForegroundColor Red -BackgroundColor DarkRed -NoNewLine
Write-Host (" _________ _______ ________ _________ ") -ForegroundColor White -NoNewline
Write-Host ("=") -ForegroundColor Red -BackgroundColor DarkRed
Write-Host ("=") -ForegroundColor Red -BackgroundColor DarkRed -NoNewLine
Write-Host ("|\___ ___\\ ___ \ |\ ____\|\___ ___\ ") -ForegroundColor White -NoNewline
Write-Host ("=") -ForegroundColor Red -BackgroundColor DarkRed
Write-Host ("=") -ForegroundColor Red -BackgroundColor DarkRed -NoNewLine
Write-Host ("\|___ \ \_\ \ __/|\ \ \___|\|___ \ \_| ") -ForegroundColor White -NoNewline
Write-Host ("=") -ForegroundColor Red -BackgroundColor DarkRed
Write-Host ("=") -ForegroundColor Red -BackgroundColor DarkRed -NoNewLine
Write-Host (" \ \ \ \ \ \_|/_\ \_____ \ \ \ \ ") -ForegroundColor White -NoNewline
Write-Host ("=") -ForegroundColor Red -BackgroundColor DarkRed
Write-Host ("=") -ForegroundColor Red -BackgroundColor DarkRed -NoNewLine
Write-Host (" \ \ \ \ \ \_|\ \|____|\ \ \ \ \ ") -ForegroundColor White -NoNewline
Write-Host ("=") -ForegroundColor Red -BackgroundColor DarkRed
Write-Host ("=") -ForegroundColor Red -BackgroundColor DarkRed -NoNewLine
Write-Host (" \ \__\ \ \_______\____\_\ \ \ \__\") -ForegroundColor White -NoNewline
Write-Host ("=") -ForegroundColor Red -BackgroundColor DarkRed
Write-Host ("=") -ForegroundColor Red -BackgroundColor DarkRed -NoNewLine
Write-Host (" \|__| \|_______|\_________\ \|__|") -ForegroundColor White -NoNewline
Write-Host ("=") -ForegroundColor Red -BackgroundColor DarkRed
Write-Host ("=") -ForegroundColor Red -BackgroundColor DarkRed -NoNewLine
Write-Host (" \|_________| ") -ForegroundColor White -NoNewline
Write-Host ("=") -ForegroundColor Red -BackgroundColor DarkRed
Write-Host ("==" * 23) -ForegroundColor Red -BackgroundColor DarkRed
Write-Host ("`n")
}
# - WARNING Read Host Confirmation
function warningConfirm() {
param
(
[Parameter(Position = 0, ValueFromPipeline = $true)]
[string]$msg,
[string]$BackgroundColor = "White",
[string]$ForegroundColor = "Red"
)
Write-Host -ForegroundColor $ForegroundColor -BackgroundColor $BackgroundColor -NoNewline $msg;
return Read-Host
}
# - Read Host Confirmation
function confirm() {
param
(
[Parameter(Position = 0, ValueFromPipeline = $true)]
[string]$msg,
[string]$BackgroundColor = "Yellow",
[string]$ForegroundColor = "Black"
)
Write-Host -ForegroundColor $ForegroundColor -BackgroundColor $BackgroundColor -NoNewline $msg;
return Read-Host
}
# - Text Colors
function text() {
param
(
[Parameter(Position = 0, ValueFromPipeline = $true)]
[string]$msg,
[string]$BackgroundColor = "Yellow",
[string]$ForegroundColor = "Black"
)
Write-Host -ForegroundColor $ForegroundColor -BackgroundColor $BackgroundColor -NoNewline $msg;
}
clear
logo
$continue = 0
while ( $continue -eq 0 ) {
$opt = (Get-Host).PrivateData
$opt.WarningBackgroundColor = "Red"
$opt.WarningForegroundColor = "White"
Write-Warning "This version of Test is for use on 2008R2 servers only."
warningConfirm ("`nConfirm you are using the correct version by pressing 'Enter'")
clear
logo
confirm ("`nTest is initiating procedures... To being processing Test jobs press > > Enter:")
text ("Gathering information to run checks. . . `(Approx. 43 Jobs`)`n")
$continue = 1
}```