Author Posts

May 2, 2018 at 8:02 am

Hello Everyone,

I'm trying to create a menu system using PowerShell.

This is achievable as per this URL:

http://www.tomsitpro.com/articles/powershell-interactive-menu,2-961.html

What I need to do next is have the ability to customize the menu so I can call another ps1 file.

For example adding this ps1:

https://gallery.technet.microsoft.com/office/AD-and-mailbox-from-CSV-96a4713f

Do I use dot notation? If so, how do I achieve that?

Or should I use some other method?

Sorry if this is a basic question. I have tried to investigate but have not been able to come up with anything.

Regards, Darren

May 2, 2018 at 8:45 am

Assuming the script you wish to run is in the same directory as you main script, you could do something like this in your on click event

Invoke-Expression .\powershellscripttorun.ps1

May 2, 2018 at 9:03 am

All you need in in the scripts you point to.
All you need to do is add a call to the script.
There are several ways to do that

From your sample pointers

    function Show-Menu
     {
          param (
                [string]$Title = 'My Menu'
          )
          cls
          Write-Host "================ $Title ================"
      
          Write-Host "1: Press '1' for this option."
          Write-Host "2: Press '2' for this option."
          Write-Host "3: Press '3' for this option."
          Write-Host "Q: Press 'Q' to quit."
     }

    do
    {
          Show-Menu
          $input = Read-Host "Please make a selection"
          switch ($input)
          {
                '1' {
                     cls
                     'You chose option #1'
                     # Run this script
                     Start-Process -FilePath powershell 'D:\Scripts\HelloWorld.ps1' -Wait
                } '2' {
                     cls
                     'You chose option #2'
                     Invoke-Expression -Command 'D:\Scripts\HelloWorld.ps1'
                } '3' {
                     cls
                     'You chose option #3'
                     & 'D:\Scripts\HelloWorld.ps1'
                } 'q' {
                     return
                }
          }
          pause
     }
     until ($input -eq 'q')

May 2, 2018 at 9:19 am

Thank you Simon B and postanote. I presumed it was something simple. Live and learn. Much appreciated. 🙂

May 2, 2018 at 9:28 am

Thank you postanote. I presumed it was something simple. Live and learn. Much appreciated. 🙂