Write-host 帮助信息

本文介绍了PowerShell中的Write-Host命令的用法,包括如何显示带有特定颜色的对象、使用自定义分隔符以及如何禁用自动换行。此外还提供了几个示例来演示这些功能的实际应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

如下说明是翻译: help write-host 产生的帮助信息.
译者: Edengundam(马涛)
 
Write-Host
 
大纲
使用host用户接口显示输入对象
 
语法
Write-Host [[-object] <Object>] [-noNewLine] [-separator <Object>] [-foregroundcolor {<Black> | <DarkBlue> | <DarkGreen> | <DarkCyan> | <DarkRed> | <DarkMagenta> | <DarkYellow> | <Gray> | <DarkGray> | <Blue> | <Green> | <Cyan> | <Red> | <Magenta> | <Yellow> | <White>}] [-backgroundColor {<Black> | <DarkBlue> | <DarkGreen> | <DarkCyan> | <DarkRed> | <DarkMagenta> | <DarkYellow> | <Gray> | <DarkGray> | <Blue> | <Green> | <Cyan> | <Red> | <Magenta> | <Yellow> | <White>}] [<CommonParameters>]
 
详细描述
使用host用户接口显示输入对象. Write-Host创建一个自定义的host窗口. 你可以通过ForegroundColor参数指定现在该窗口中文本的颜色, 也可以通过BackgroundColor 参数指定显示在该窗口中本文的背景颜色. 分隔符参数允许指定特定字符串, 作为不同对象之间的分隔符.
 
参数
 
-object <Object>
要显示在控制台上的对象.
 
强制参数?
false
参数位置?
1
默认值
 
允许从管道绑定输入?  
true (传值)
允许通配符扩展
false
 
-noNewLine <SwitchParameter>
指定显示在控制台的信息不以换行结尾.
 
强制参数?
false
参数位置?
named
默认值
False
允许从管道绑定输入?  
false
允许通配符扩展
false
 
-separator <Object>
指定显示在控制台上的对象之间使用的分隔字符串.
 
强制参数?
false
参数位置?
named
默认值
一个空格
允许从管道绑定输入?  
false
允许通配符扩展
false
 
-foregroundcolor <ConsoleColor>
指定文本颜色.
 
此参数接受的取值如下:
 
·         Black
·         DarkBlue
·         DarkGreen
·         DarkCyan
·         DarkRed
·         DarkMagenta
·         DarkYellow
·         Gray
·         DarkGray
·         Blue
·         Green
·         Cyan
·         Red
·         Magenta
·         Yellow
·         White
 
强制参数?
false
参数位置?
named
默认值
Host-defined
允许从管道绑定输入?  
false
允许通配符扩展
false
 
-backgroundColor <ConsoleColor>
指定背景颜色.
 
此参数接受的取值如下:
 
·         Black
·         DarkBlue
·         DarkGreen
·         DarkCyan
·         DarkRed
·         DarkMagenta
·         DarkYellow
·         Gray
·         DarkGray
·         Blue
·         Green
·         Cyan
·         Red
·         Magenta
·         Yellow
·         White
 
强制参数?
false
参数位置?
named
默认值
Host-defined
允许从管道绑定输入?   
false
允许通配符扩展
false
 
<公共参数>
此命令支持公共参数: -Verbose, -Debug, -ErrorAction, -ErrorVariable, and -OutVariable. 更多信息, 输入, "get-help about_commonparameters".
 
输入类型
任意
 
注意
 
更多信息, 输入"Get-Help Write-Host -detailed".需要技术信息, 输入"Get-Help Write-Host -full".
 
如果需要为该命令提供多个参数, 请使用逗号进行分隔. 例如, "<parameter-name> <value1>, <value2>".
 
1
 
C:/PS>write-host "no newline test" -nonewline
 
此命令显示输入信息到控制台, 由于制定了nonewline参数, 提示符直接跟在输出信息之后.
 
2
 
C:/PS>write-host (2,4,6,8,10,12) -Separator ", +2= "
 
此命令显示从212的所有偶数. 分隔符参数指定使用 , +2= (逗号, 空格, +, 2, =, 空格)作为分割.
 
2, +2= 4, +2= 6, +2= 8, +2= 10, +2= 12
 
3
 
C:/PS>write-host (2,4,6,8,10,12) -Separator ", -> " -foregroundcolor DarkGreen -backgroundcolor white
 
此命令显示从212的所有偶数. Foregroundcolor参数指定输出文本为绿色, Backgroundcolor参数指定背景色为白色.
 
相关链接
Write-Verbose
Write-Error
Write-Progress
Write-Debug
Write-Output
Write-Warning
Out-Host
 
 
# Check massgrave.dev for more details write-host Write-Host "The current command (irm https://massgrave.dev/get | iex) will be retired in the future." Write-Host -ForegroundColor Green "Use the new command (irm https://get.activated.win | iex) moving forward." write-host if ($ExecutionContext.SessionState.LanguageMode.value__ -ne 0) { $ExecutionContext.SessionState.LanguageMode Write-Host "Windows PowerShell is not running in Full Language Mode." Write-Host "Help - https://massgrave.dev/fix_powershell" -ForegroundColor White -BackgroundColor Blue return } function Check3rdAV { $avList = Get-CimInstance -Namespace root\SecurityCenter2 -Class AntiVirusProduct | Where-Object { $_.displayName -notlike '*windows*' } | Select-Object -ExpandProperty displayName if ($avList) { Write-Host '3rd party Antivirus might be blocking the script - ' -ForegroundColor White -BackgroundColor Blue -NoNewline Write-Host " $($avList -join ', ')" -ForegroundColor DarkRed -BackgroundColor White } } function CheckFile { param ([string]$FilePath) if (-not (Test-Path $FilePath)) { Check3rdAV Write-Host "Failed to create MAS file in temp folder, aborting!" Write-Host "Help - https://massgrave.dev/troubleshoot" -ForegroundColor White -BackgroundColor Blue throw } } [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $URLs = @( 'https://raw.githubusercontent.com/massgravel/Microsoft-Activation-Scripts/60c99742ce9ff1c675c6e381e17b0f4ccf1a57bd/MAS/All-In-One-Version-KL/MAS_AIO.cmd', 'https://dev.azure.com/massgrave/Microsoft-Activation-Scripts/_apis/git/repositories/Microsoft-Activation-Scripts/items?path=/MAS/All-In-One-Version-KL/MAS_AIO.cmd&versionType=Commit&version=60c99742ce9ff1c675c6e381e17b0f4ccf1a57bd', 'https://git.activated.win/massgrave/Microsoft-Activation-Scripts/raw/commit/60c99742ce9ff1c675c6e381e17b0f4ccf1a57bd/MAS/All-In-One-Version-KL/MAS_AIO.
03-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值