gpt4 book ai didi

colors - Powershell中字符串的颜色部分

转载 作者:行者123 更新时间:2023-12-05 08:19:07 29 4
gpt4 key购买 nike

我试图只给字符串“None Provided”着色,而不是整行着色。

到目前为止我有:

$owned | % {write-host "Managing Group: " + ("None Found" -foreground red) "Group Description: None Provided"}

问题出在 () 中的 -foreground,'f' 变灰会导致错误。它在没有 () 的情况下工作(通过给整条线着色)。你能帮我只给“None Found”上色吗

通过使用 Overflowed 的回答,它帮助我解决了这个问题。谢谢!

编辑:

if ($owned -eq $Null){
$owned | % {write-host "Managing Group: " -nonewline}
$owned | % {write-host "None Found " -foreground red -nonewline}
$owned | % {write-host "Group Description: " -nonewline}
$owned | % {write-host "None Provided " -foreground red}
}

elseif ($description -eq $Null){
$owned | % {write-host "Managing Group: "($_.name) "Group Description: " -nonewline}
$owned | % {write-host "None Provided " -foreground red}
}

else {
$owned | % {write-host "Managing Group: "($_.name) "Group Description: " ($_.description -replace "`r`n", " ")}
}

最佳答案

通过 -nonewline 开关使用多个写入主机

write-host "Managing Group: " -nonewline
write-host "None Found" -foreground red -nonewline
write-host "Group Description: None Provided"

关于colors - Powershell中字符串的颜色部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27689678/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com