How can I call a ps1 within a ps1?

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

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

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')

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

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