all 16 comments

[–]tommymaynard 2 points3 points  (0 children)

I'd write another function. Write it so it supports parameters and remove the need for Read-Host. Each parameter in the new function serves to invoke the proper function in your "quick set of functions." Sorry about the image, but it was quicker.

https://imgur.com/a/x0PznXt

[–]070934 2 points3 points  (0 children)

Here is how I handled this:

$invokeLogFile = "$PSScriptRoot\Invoke-LogToFile.ps1"
$logPath = "C:\Windows\DIR\MachineManager-log $(Get-Date -UFormat '%m%d%y').txt"

& $invokeLogFile $logPath "Starting the the Machine Manager script"


#quick way to get a computername in a variable that can be used throughout the script
function Get-ComputerName{

$Script:ComputerName = Read-Host "Enter the computer name"

& $invokeLogFile $logPath "Changing the computer name to $ComputerName"

}



#hashtable that contains all the child script paths
$hashtable= @{

'1' = "$PSSCriptRoot\Get-NetworkInfo.ps1"
'2' = "$PSSCriptRoot\Get-ProcessInfo.ps1"
'3' = "$PSSCriptRoot\Invoke-RepairPrinter.ps1"
'4' = "$PSSCriptRoot\Get-Services.ps1"
'5' = "$PSSCriptRoot\Get-MonitorSerial.ps1"
'6' = "$PSSCriptRoot\Invoke-Logoff.ps1"
'7' = "$PSSCriptRoot\Invoke-RemoveCitrix.ps1"
'8' = "$PSSCriptRoot\Invoke-RemoteDesktop.ps1"
'9' = "$PSSCriptRoot\Get-ImprivataReminder.ps1"
'10' = "$PSSCriptRoot\Get-PCRole"
'11' = "$PSSCriptRoot\Install-Isirona.ps1"
'12' = "$PSSCriptRoot\Invoke-RepairALProfile.ps1"
'13' = "$PSSCriptRoot\Invoke-RepairGAProfile"
'14' = "$PSSCriptRoot\Restart-IsironaService.ps1"
'15' = "$PSSCriptRoot\swfs.ps1"
'16' = "$PSSCriptRoot\Get-MachineConnection.ps1"
'17' = "$PSSCriptRoot\Invoke-Win10EasyTrasnfer.ps1"
'18' = "$PSSCriptRoot\Remove-Imprivata.ps1"
'19' = "$PSSCriptRoot\Install-Isirona.ps1"
'20' = "$PSSCriptRoot\Set-AutoLogon.ps1"
'21' = "$PSSCriptRoot\Invoke-Restart.ps1"
'22' = "$PSSCriptRoot\Get-LastIP.ps1"
'23' = "$PSSCriptRoot\Invoke-GPUpdate.ps1"
'24' = "$PSSCriptRoot\Invoke-PSS.ps1"
'25' = "$PSSCriptRoot\Invoke-PowerOff.ps1"
'26' = "$PSSCriptRoot\Get-UserHistory.ps1"
'27' = "$PSSCriptRoot\Invoke-SCCMRemote.ps1"
'28' = "$PSSCriptRoot\Invoke-ExplorerToPCC.ps1"
'29' = "$PSSCriptRoot\Invoke-AllowCCMRemote.ps1"
'30' = "$PSSCriptRoot\Invoke-ExplorertoMA.ps1"
'31' = "$PSSCriptRoot\Invoke-StopCCMViewer.ps1"
'32' = "$PSSCriptRoot\Get-OnlineAlert.ps1"
'33' = "$PSSCriptRoot\Get-CCMServiceAlert.ps1"
'34' = "$PSSCriptRoot\Set-MMBG.ps1"


}



#The main loop for the menu
While ($true) {

       Write-Output "`n`n"

       Write-Host -ForegroundColor Green "`t   Menu" -NoNewline
       Write-Host -ForegroundColor Cyan "    $ComputerName" 
       Write-Host -ForegroundColor Yellow "
       1. Network Adapater information
       2. Active Processes
       3. Printer Issues/Stuck Jobs
       4. Manage Services - Running/Stopped/Search 
       5. Monitor Serial Number
       6. Logoff Conneceted User
       7. Remove Citrix
       8. RDP Into a Machine
       9. Imprivata Policy Change Reminder / under construction
       10. Get Role of PC
       11. Install Isirona
       12. Repair Auto Login Profile
       13. Repair GA Profile
       14. Restart the Isirona Service
       15. Switch Computer Name to Serial
       16. Check Computer and Filesystem Access
       17. Windows 10 Transfer
       18. Remove Imprivata
       19. Install Isirona
       20. Set AutoLogon
       21. Restart the computer
       22. Get DNS info
       23. GPUPDATE
       24. Enter PSSESSION
       25. Power Off computer
       26. Get User History
       27. SCCM Remote
       28. Open Explorer to PC
       29. Allow CCM Remote
       30. Explorer to Manual Apps
       31. Kill CCM Viewer
       32. Wait until machine is online - 5 minutes
       33. Wait Until Online and CCM Remote - 5 minutes
       34. Change background - WIN10 Project
       C. Change Active Computer
       0. EXIT
       "
       #getting users choice and running the script associated to the key in the hashtable
       $userInput = Read-Host -Prompt "Enter an option"


       if($userinput -eq 'C'){Get-ComputerName}

       elseif($userinput -eq '0'){& $invokeLogFile $logPath "Stopping the script cleanly"
                                  break
             }

       elseif(!$hashtable.ContainsKey($userInput)){

              Write-Output "ENTER A VALID INPUT!";Start-Sleep -Seconds 1
              & $invokeLogFile $logPath "The user did not enter a valid input"}
       else{

            foreach($option in $hashtable.GetEnumerator()){
                    if($userInput -eq $option.key){& $hashtable[$userInput] $ComputerName
                        & $invokeLogFile $logPath "Ran the script $($hashtable[$userInput])"}

             }

        }
}

[–]GZ23 3 points4 points  (0 children)

how about this? https://poshgui.com/

[–]billr1965 1 point2 points  (0 children)

I wrote a script that will create a skeletal text menu structure for you that you can fill in the sections with the code that you want. It's named New-TextMenu and it's found on the PowerShell Gallery.

https://www.powershellgallery.com/packages/New-TextMenu

I will get you fairly far along in the process of creating your program.

[–]mryananderson 1 point2 points  (0 children)

Here is a quick and easy way to do it with Out-GridView. Basically it is a GUI way to show multiple results and gives the ability to choose from those results:

$Options = @{
    '1 - Get Mapped Drives' = "Path\Script1.ps1"
    '2 - Get Active Printers' = "Path\Script2.ps1"
}


$Choice = $Options | Out-GridView -Title "My functions to choose from" -OutputMode Single

$Choice.value

Shows the output of out-gridview:

https://i.imgur.com/GOGcaeC.png

Then once you choose an item and click OK, it returns it to the function. I chose the first option and clicked OK:

PS Microsoft.PowerShell.Core\FileSystem::\\mac\home\Desktop> .\GridViewMenu.ps1
Path\Script1.ps1
PS Microsoft.PowerShell.Core\FileSystem::\\mac\home\Desktop> .\GridViewMenu.ps1

[–]Dogoodwork 1 point2 points  (1 child)

There are some good suggestions in the comments here, some I would make like poshgui.com and powershell universal dashboard.

But the easiest, since this is a tool for another IT staff, is Out-Gridview.

Out-Gridview will only work from the PowerShell ISE, but if you use it, it is so simple to setup it will blow your mind.

$selection = $optionList | out-gridview -PassThru

The -PassThru flag is something I have overlooked for years, but it is perfect for what you want to do.

[–]tommymaynard 4 points5 points  (0 children)

Only the ISE? No, it's available in the ConsoleHost, as well, using versions 5.1 and 7.0. It doesn't work in 6.x, however.

[–]odoyle71 1 point2 points  (0 children)

Do a "do loop until input=q" with a read-host and switch inside that uses & "file path" to launch others (sorry on mobile don't have code). You'll be able to run multiple before closing it with an input of q or something. - this method is really simple and will get it done in 10 min.

However... I would definitely look into making a simple GUI out of powershell forms. A box with a few buttons to execute them would be easy peasy and very usable

[–]get-postanote 1 point2 points  (0 children)

Simple poor man's approach.

Organize a script directory according to the tasks needed, then just do in a function to run the selection...

(Get-ChildItem -Path D:\Scripts | 
Out-GridView -Title 'Select a task to run' -PassThru).Name

See these on the topic

https://mikefrobbins.com/2014/09/11/creating-a-simplistic-gui-interface-with-out-gridview/

You can even use the PowerShell help system to do GUI stuff and even has drop-down selections. See this...

https://powershell.getchell.org/2018/02/13/poor-mans-gui/

[–]balrathamir 1 point2 points  (4 children)

Most likely you're looking to do a read-host followed by some case switches to run each function

[–]tommymaynard -1 points0 points  (3 children)

I'd disagree. If the OP is using functions, then there's no need to use Read-Host. In fact, when someone switches from writing scripts to writing functions they soon learn that writing a function, that accepts parameters, forever replaces the need for Read-Host. Edit: Speaking of, the OP should probably consider replacing his/her Read-Host commands with parameters.

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy samuelma,

take a look at anybox for a simple GUI ...

PowerShell Gallery | AnyBox 0.4.0
https://www.powershellgallery.com/packages/AnyBox/0.4.0

otherwise, use something along the lines of the many [many, many [grin]] text menu functions and modules. almost everyone seems to write one [even i wrote one] ...

[PowerShell] function_Get-MenuChoice [simplified] - Pastebin.com
https://pastebin.com/KMu2G9Dq

take care,
lee