Author Posts

December 3, 2013 at 7:01 am

Hi New to Powershell here, trying to fumble my way through...

I'm trying to write a script to output the last 3 eventlog items from named servers to an HTML file.

I want to have a prompt ask the user which servers they want to query. I can't quite work out how to handle multiple inputs, I think I need an array but not sure how to set it up. Can anyone give me any pointers?

TIA

Doug

December 3, 2013 at 7:25 am

The BEST way is to let PowerShell do it. At the top of your script:

[CmdletBinding()]
Param(
  [Parameter(Mandatory=$True)][string[]]$ComputerName
)

If someone runs the script, they'll be prompted for the computer name. They can keep entering them, one at a time, hitting Enter on an empty prompt to indicate they're done. The nice thing is that they can bypass the prompt by running the script and providing a -ComputerName parameter up front.

This remains consistent with the way the shell works for all commands.

December 3, 2013 at 7:39 am

Great, thank you Don. I'll play around with that now 🙂

December 3, 2013 at 7:53 am

Works a charm, thanks again!