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
Avatar of Jason Crawford
Jason Crawford
Flag of United States of America image

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

Avatar of SquigglyMonkey
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

Yea that Out-GridView -PassThru is just as good as a Windows Form.  Try it out.
Avatar of 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
Avatar of Jason Crawford
Jason Crawford
Flag of United States of America image

Blurred text
THIS SOLUTION IS 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
You can determine the PowerShell version by running this: $PSVersionTable.psversion
Avatar of 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?
Avatar of SquigglyMonkey

ASKER

Thanks much for this.
Glad I could help.  Take care :)
Powershell
Powershell

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.

27K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo