Script to let the users make a couple of choices, creating the actual command they need to run.

SquigglyMonkey
SquigglyMonkey used Ask the Experts™
on
What is a simple way to allow an end user to make a couple of choices to create the command they need to run?

There is 5 server/paths that need to be listed and 5 different files to open, per server/path.

the paths are like this:
\\server1\share\folder\file.day
\\server2\share\folder\file.day
\\server3\share\folder\file.day
\\server4\share\folder\file.day
\\server4\share\folder-2\file.day
file.day is .mon .tue. wed .thu  or .fri

I'd like the user to be able to choose the server\path, then the day,
Something like "Please choose 1. 2. etc, with each server/path listed, total of 5 choices.
Then choose what day it is, 1. monday 2. tuesday, etc.
Creating the command to run, which is (EX: for server1 on tuesday:)

get-filetail -path \\server\share\folder\folder\file.tues -count 1 -wait

thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
How about something like this:

$server = @(
  '\\server1'
  '\\server2'
  '\\server3'
  '\\server4'
  '\\server5'
) | Out-GridView -PassThru

$share = @(
  '\share\folder1'
  '\share\folder2'
  '\share\folder3'
  '\share\folder4'
  '\share\folder5'
) | Out-GridView -PassThru

$file = @(
  '\file.mon'
  '\file.tues'
  '\file.wed'
  '\file.thurs'
  '\file.fri'
) | Out-GridView -PassThru

$result = $server + $share + $file

Get-FileTail -Path $result -Count 1 -Wait

Open in new window

Author

Commented:
Thankyou, I'll try that, I was about to pst what I was starting to come up with, I found a menu function but wasn't getting very far with it.
function Show-Menu
{
     param (
           [string]$Title = 'Menu1'
     )
     cls
     Write-Host "================ Server-Path ================"
     
     Write-Host "1: Press '1' for Server1."
     Write-Host "2: Press '2' for this option."
     Write-Host "3: Press '3' for this option."
     Write-Host "4: Press '4' for this option."
     Write-Host "5: Press '5' for this option."
	Write-Host "Q: Press 'Q' to quit."
}
do
{
     Show-Menu
     $input = Read-Host "Please make a selection"
     switch ($input)
     {
             '1' {'server1'
                
                
           } '2' {
                
                'You chose option #2'
           } '3' {
                
                'You chose option #3'
           } '4' {
                
                'You chose option #4'
           }
             'q' {test
                return
           }
     }
     pause
}
until ($input -eq 'q')

Open in new window

Commented:
Yea that Out-GridView -PassThru is just as good as a Windows Form.  Try it out.
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Author

Commented:
Do I need to run this some way other than to copy your code into a ps1 file and run that file from within powershell?
When I do, nothing 'prompts' or 'pops up'.
Commented:
Doh you must be running version 2.0.  I forgot the #requires statement:

#requires -version 3.0
$server = @(
  '\\server1'
  '\\server2'
  '\\server3'
  '\\server4'
  '\\server5'
) | Out-GridView -PassThru

$share = @(
  '\share\folder1'
  '\share\folder2'
  '\share\folder3'
  '\share\folder4'
  '\share\folder5'
) | Out-GridView -PassThru

$file = @(
  '\file.mon'
  '\file.tues'
  '\file.wed'
  '\file.thurs'
  '\file.fri'
) | Out-GridView -PassThru

$result = $server + $share + $file
Get-FileTail -Path $result -Count 1 -Wait

Open in new window

Commented:
You can determine the PowerShell version by running this: $PSVersionTable.psversion

Author

Commented:
Derp.... Ver 4, but needed to be 'run as admin'.
Works good, is there a way to reduce the real-estate that out-grid is taking up?

Author

Commented:
Thanks much for this.

Commented:
Glad I could help.  Take care :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial