Powershell 脚本,写入输出

Powershell script, write-output

我需要编写一个 PowerShell 脚本来执行以下操作, "Lab assignment: Write a PowerShell script that prompts the user to enter their first and last name then prints back out a greeting with their name in it (e.g. Hello, John Anderson). Proper script formatting will be 50% of your grade. "

PowersSell 和脚本的全新内容。非常感谢帮助。

我试过使用写输出命令

Write-Output "Hello " (Read-Host -Prompt 'What is your name?')

我得到输入名称的提示,但输出在 2 个不同的行上

我需要它们在同一行并打印。

提示符(Read-Host -Prompt ...)是传递给Write-Output2nd参数;相反,您希望它位于 1st(且仅)参数中,即 "Hello " 字符串。

这将起作用:

Write-Output "Hello $(Read-Host -Prompt 'What is your name?')"