We help IT Professionals succeed at work.

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

SquigglyMonkey
on
88 Views
Last Modified: 2017-04-05
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

Jason CrawfordTransport Ninja
CERTIFIED EXPERT

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

Jason CrawfordTransport Ninja
CERTIFIED EXPERT

Commented:
Yea that Out-GridView -PassThru is just as good as a Windows Form.  Try it out.

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'.
Transport Ninja
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Jason CrawfordTransport Ninja
CERTIFIED EXPERT

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.
Jason CrawfordTransport Ninja
CERTIFIED EXPERT

Commented:
Glad I could help.  Take care :)