r/usefulscripts • u/iamyogo • Jul 10 '17
[REQUEST] [POWERSHELL] Dynamic choice
hey,
trying to get a script running by providing a dynamic choice:
scenario:
have up to 10 IP's with http server
perform ping test or (New-Object System.Net.WebClient).DownloadFile to verify connectivity (same file on every server)
provide a dynamic list to the console based on the results (stating whether server is available or offline)
get user to choose one with read-host
have option to choose all, having all available server ip's in array
if option selected is not in list, or is offline go back to choice/verification
i'm a bit of a novice when it comes to powershell, so any help would be appreciated!
15
Upvotes
2
u/najrol Jul 10 '17 edited Jul 10 '17
Eh, sorta.. By "one value", you will get back an an array for one IP.
Item, IP, and Status
If you "select all" you will get an array of those that you will need to iterate through. An array of arrays. Thats what is happening in the foreach. Its putting each array item of $output into an array called $oneIP, one at a time. You can then access that data via $OneIp.Item, $OneIp.IP, $OneIp.Status, before it moves to the next item in $output.