Admittedly, reading input given by the user at the host is not among the best things for automation. However, in some situations, it is necessary. Let's not leave such stones unturned, at least. In this recipe, we will ask the user for their name, and then display the greeting along with the date. Optionally, you can have a space in the name of the script.
Reading input from the host
How to do it...
This is straightforward. If you are comfortable using command discovery, you can simply use get-command *host to get the information. Modify the script we created for the Writing a simple script recipe to get the desired script:
Get-Date hostname Write-Output "Hello, $(Read-Host "Enter your name")!" ...