Calling Powershell script in ISE mode

DHoss 61 Reputation points
2023-02-12T21:44:03.7033333+00:00

Hi All,

I have a powershell script which is called from a powershell scripts using the following command:

Start-Process powershell_ISE "$PSScriptRoot!AD_UsrGrp_Chk.ps1"

It works fine as it should. It open the script in PowerShell ISE mode but stop there. I want it to run the script at the same time without any click. I was just wondering if anyone can give a any suggestions if it is possible. Currently it looks like this:

image

I want this to run automatically.

Any help would be much appreciated.

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Reza Aghaei 4,986 Reputation points MVP Volunteer Moderator
    2023-02-13T03:11:56.09+00:00

    You can use SendKeys to send a F5 key to the process like this, let's say it's the content of main.ps1:

    Add-Type -AssemblyName System.Windows.Forms
    Start-Process powershell_ISE "$PSScriptRoot\test.ps1"
    # Wait a bit
    Start-Sleep -Seconds 2
    # Press F5
    [System.Windows.Forms.SendKeys]::SendWait("{F5}")
    

    Then it opens the test.ps1 file which I assume is located beside the current script.

    Note: Do not test this solution in ISE, because once the main script is running, it cannot run test.ps1. So, to test, in a shell command line, run the main script like this:

    powershell.exe c:\myfiles\main.ps1
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.