Link to home
Start Free TrialLog in
Avatar of ndalmolin_13
ndalmolin_13Flag for United States of America

asked on

How can I configure a read-host statement in powershell to accept input that contains spaces

Hello Powershell Experts,

I'm working on a script that will update some AD information for users.  I identify the user that for which the script will run with a read-host statement.  The read-host statement is currently configured as:

read-host "Input the username"

I would input nickd (as our usernames are firstname + first initial of the last name") and everything works fine.

I want to change the read-host statement to:
read-host "Input the first and last name"

How can I do this?  The space between the firstname and the lastname are causing issues.

Thanks in advance.
Nick
ASKER CERTIFIED SOLUTION
Avatar of Aard Vark
Aard Vark
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In which way is that an issue? The whole input is considered to be a single string.
Do you need to split it into first and last name? Without any check, -split is the simplest way to do so:
$first, $last = (read-host "Input the first and last name") -split " "

Open in new window