1

I am creating a power-shell module with multiple functions , one of which needs a user input in middle of the run. how to use function to request an input without supplying it as a parameter? Is it even possible?

Darktux
  • 827
  • 5
  • 21
  • 36

1 Answers1

6

You tagged your question , so if you need to supply a SecureString as a parameter somewhere, you should use the Get-Cred command.

To get just a simple string, use Read-Host.

However, I personally find scripts that use Read-Host and Write-Host (and even Get-Cred) to be painful to use. You SHOULD be writing scripts to accept parameters. Then your scripts can be re-used for further automation. If you really want it to prompt for user input, then I suggest two scripts: one that has all of the actual functionality in it and accepts parameters or pipeline input, and the other that simply prompts for user input and calls the second.

longneck
  • 23,082
  • 4
  • 52
  • 86