Powershell 如何更改测试连接输出的输出颜色
我需要根据Powershell 如何更改测试连接输出的输出颜色,powershell,colors,output,Powershell,Colors,Output,我需要根据测试连接-quiet cmdlet的输出更改文本的颜色 如果为真绿色,如果为假红色 我尝试使用write主机,但运气不佳 $StartIP = Read-Host -Prompt 'Input Start IP' $EndIP = Read-Host -Prompt 'Input End IP' $results= ([int]$StartIP..[int]$EndIP) | % {"192.168.128.$($): $(Test-Connection -count 1 -comp
测试连接
-quiet cmdlet的输出更改文本的颜色
如果为真绿色,如果为假红色
我尝试使用write主机,但运气不佳
$StartIP = Read-Host -Prompt 'Input Start IP'
$EndIP = Read-Host -Prompt 'Input End IP'
$results= ([int]$StartIP..[int]$EndIP) | % {"192.168.128.$($): $(Test-Connection -count 1 -comp 192.168.128.$($) -quiet)"}
Read-Host -Prompt "Press Enter to exit"
遵循您现有的代码:
$start = (Read-Host -Prompt Start) -as [int]
$end = (Read-Host -Prompt End) -as [int]
$start..$end | ForEach-Object {
$ip = "192.168.128.$_"
if (Test-Connection -Count 1 -Quiet -ComputerName $ip) {
"$ip TRUE" | Write-Host -ForegroundColor Green
}
else {
"$ip FALSE" | Write-Host -ForegroundColor Red
}
}
遵循您现有的代码:
$start = (Read-Host -Prompt Start) -as [int]
$end = (Read-Host -Prompt End) -as [int]
$start..$end | ForEach-Object {
$ip = "192.168.128.$_"
if (Test-Connection -Count 1 -Quiet -ComputerName $ip) {
"$ip TRUE" | Write-Host -ForegroundColor Green
}
else {
"$ip FALSE" | Write-Host -ForegroundColor Red
}
}
您没有使用写主机,输出也会转到变量-您希望颜色显示在哪里?您没有使用写主机,输出也会转到变量-您希望颜色显示在哪里?谢谢@那些不可救药的手帕@他们是不可救药的