Bodrick Butler
Bodrick Butler

Reputation: 13

Powershell script, write-output

I need to write a PowerShell script to do the following, "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. "

brand new to PowersSell and scripting. help is very appreciated.

I have tried using the write-output cmd

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

I get the prompt to enter name but the output is on 2 different lines

I need them on the same line and to print.

Upvotes: 1

Views: 798

Answers (1)

Jonathan Larouche
Jonathan Larouche

Reputation: 992

The prompt (Read-Host -Prompt ...) is the 2nd argument passed to Write-Output; instead, you want it inside the 1st (and only) argument, the "Hello " string.

This will work:

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

Upvotes: 1

Related Questions