相关疑难解决方法(0)

PowerShell中的多个前景色在一个命令中

我想用一个语句输出许多不同的前景色.

PS C:\> Write-Host "Red" -ForegroundColor Red
Red
Run Code Online (Sandbox Code Playgroud)

此输出为红色.

PS C:\> Write-Host "Blue" -ForegroundColor Blue
Blue
Run Code Online (Sandbox Code Playgroud)

此输出为蓝色.

PS C:\> Write-Host "Red", "Blue" -ForegroundColor Red, Blue
Red Blue
Run Code Online (Sandbox Code Playgroud)

这个输出是洋红色的,但我希望红色这个词的颜色是红色,而通过一个命令我想要蓝色代表蓝色.我怎样才能做到这一点?

powershell colors

51
推荐指数
6
解决办法
7万
查看次数

某些结果的输出格式-表格线颜色

我运行下面的代码,它的工作原理:

Get-ChildItem -Path T: -Filter *.pfx | ForEach-Object { 
    Import-PfxCertificate -FilePath $_.FullName -CertStoreLocation Cert:\CurrentUser\My -Password ****** -Force -AsPlainText) -Exportable 
} |
Format-Table -Property @{Label="Computador"; Expression={$env:computername}},
    @{Label="Nome"; Expression={$_.FriendlyName}},
    @{Label="Validade"; Expression={$_.NotAfter}},
    @{Label="Impressão digital"; Expression={$_.Thumbprint}} -AutoSize
Run Code Online (Sandbox Code Playgroud)

我试图用红色的过期证书来写每一行。如果我试试这个:

Get-ChildItem -Path T: -Filter *.pfx | ForEach-Object { 
    Import-PfxCertificate -FilePath $_.FullName -CertStoreLocation Cert:\CurrentUser\My -Password ****** -Force -AsPlainText) -Exportable 
} |
Format-Table -Property @{Label="Computador"; Expression={$env:computername}},
    @{Label="Nome"; Expression={$_.FriendlyName}},
    @{Label="Validade"; Expression={$_.NotAfter}},
    @{Label="Impressão digital"; Expression={$_.Thumbprint}} -AutoSize |
Out-String | Write-Host -ForegroundColor Red
Run Code Online (Sandbox Code Playgroud)

所有线条都变成红色。如果我尝试将 $_ 值传递给 If,控制台会说这是一个 Null 值。

有什么建议?


我想做的事情的解决方案是由 …

powershell

1
推荐指数
1
解决办法
1530
查看次数

标签 统计

powershell ×2

colors ×1