You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在PowerShell中实现类似Python Input的功能?

PowerShell 中实现 Python input() 的等效功能

你对Read-Host的理解有误,它正是PowerShell里对应Pythoninput()的命令——既能显示提示信息,又能接收用户输入并返回输入内容。

对应你给出的Python代码:

searched_user = str(input('Please input your AD user name: '))

PowerShell的等效写法是:

$searched_user = Read-Host -Prompt 'Please input your AD user name'

补充说明:

  • Read-Host返回的本身就是字符串类型,无需额外转换,和Pythoninput()的行为完全匹配
  • 后续可以直接通过$searched_user变量调用用户输入的内容,进行AD查询等后续操作

内容的提问来源于stack exchange,提问作者user19086677

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 20:25:53