Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8825165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:48:50+00:00 2026-06-14T06:48:50+00:00

I have many scripts. After making changes, I like to run them all to

  • 0

I have many scripts. After making changes, I like to run them all to see if I broke anything. I wrote a script to loop through each, running it on fresh data.

Inside my loop I’m currently running powershell.exe -command <path to script>. I don’t know if that’s the best way to do this, or if the two instances are totally separate from each other.

What’s the preferred way to run a script in a clean instance of PowerShell? Or should I be saying “session”?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:48:51+00:00Added an answer on June 14, 2026 at 6:48 am

    Using powershell.exe seems to be a good approach but with its pros and cons, of course.

    Pros:

    • Each script is invoked in a separate clean session.
    • Even crashes do not stop the whole testing process.

    Cons:

    • Invoking powershell.exe is somewhat slow.
    • Testing depends on exit codes but 0 does not always mean success.

    None of the cons is mentioned is a question as a potential problem.

    The demo script is below. It has been tested with PS v2 and v3. Script names
    may include special characters like spaces, apostrophes, brackets, backticks,
    dollars. One mentioned in comments requirement is ability to get script paths
    in their code. With the proposed approach scripts can get their own path as
    $MyInvocation.MyCommand.Path

    # make a script list, use the full paths or explicit relative paths
    $scripts = @(
        '.\test1.ps1' # good name
        '.\test 2.ps1' # with a space
        ".\test '3'.ps1" # with apostrophes
        ".\test [4].ps1" # with brackets
        '.\test `5`.ps1' # with backticks
        '.\test $6.ps1' # with a dollar
        '.\test ''3'' [4] `5` $6.ps1' # all specials
    )
    
    # process each script in the list
    foreach($script in $scripts) {
        # make a command; mind &, ' around the path, and escaping '
        $command = "& '" + $script.Replace("'", "''") + "'"
    
        # invoke the command, i.e. the script in a separate process
        powershell.exe -command $command
    
        # check for the exit code (assuming 0 is for success)
        if ($LastExitCode) {
            # in this demo just write a warning
            Write-Warning "Script $script failed."
        }
        else {
            Write-Host "Script $script succeeded."
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have many lines in my script that look like: ./run -f abc.txt ./run
I have many Transact-SQL (SQL 2005) scripts in a folder meant to run as
I have many scripts in a directory that all start with deploy_ (for instance,
I have a sed(1) script doing many step-by-step transformations (substitutions) of a given input
I have written a Python script for merging many data files in a few
I have a simple script to check how many files a user has uploaded:
I have the following script $(function(){ $('.input1_class, .input2_class, <many other input classes go here>').bind('change',
I have many many files in a folder, and I want to process them
I have many directories with files in them. I want to create a comma
I have page with many doubleclick scripts I have js code inserted at the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.