1

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.

2
  • 3
    SO isn't a script writing service, but I can give you some pointers. I would recommend breaking your script into multiple lines. Maybe store the user input into a variable and then output that variable in your Write-Output line Commented Sep 9, 2019 at 20:35
  • 1
    Read Get-Help Write-Output and then omit it completely, concatenating the two strings with a + => "Hello "+(Read-Host -Prompt 'What is your name?') Commented Sep 9, 2019 at 20:45

1 Answer 1

1

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?')"

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.