Avatar of SquigglyMonkey
SquigglyMonkey
 asked on

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

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!
Powershell

Avatar of undefined
Last Comment
Jason Crawford

8/22/2022 - Mon
Jason Crawford

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

SquigglyMonkey

ASKER
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

Jason Crawford

Yea that Out-GridView -PassThru is just as good as a Windows Form.  Try it out.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
SquigglyMonkey

ASKER
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'.
ASKER CERTIFIED SOLUTION
Jason Crawford

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Jason Crawford

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

ASKER
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?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SquigglyMonkey

ASKER
Thanks much for this.
Jason Crawford

Glad I could help.  Take care :)