《Learn Windows PowerShell in a Month of Lunches Third Edition》读书笔记—CHAPTER 19 Input and output

19.2 Read-Host

Read-Host 用来收集用户输入

PS C:\> read-host "Enter a computer name"
Enter a computer name: SERVER-R2
SERVER-R2

我们可以将输入的值保存到变量中:

PS C:\> $computername = read-host "Enter a computer name"
Enter a computer name: SERVER-R2

使用ISE则会弹出对话框。
当然,我们也可以在cli中弹出对话框:
Creating a graphical input box in Windows PowerShell

19.3 Write-Host

我们可以使用 Write-Host 来展示输出。可以使用 -foregroundColor-backgroundColor 参数改变输出的前景色和背景色。

PS C:\> write-host "COLORFUL!" -fore yellow -back magenta
COLORFUL!

Write-Host runs in the pipeline like any other cmdlet, but it doesn’t place anything into the pipeline. Instead, it writes directly to the hosting application’s screen.

19.4 Write-Output

Write-Output 将对象送入pipeline中,最终是pipeline本身展示这些对象。
因此,由于不是 Write-Output 本身对对象进行展示,就不允许我们指定输出的颜色。

19.5 Other ways to write

Alternative output cmdlets

如果我们想要使用上述的一些Write cmdlet,需要先允许使用他们。比如,设置$VerbosePreference="Continue"来允许 Write-Verbose

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值