how to stop command prompt window from appearing when running PowerShell script?

  • Hi everyone

    I have a PowerShell script that is run by Execute Process Task in SSIS.  Each time I run the task I get a black windows prompt screen appearing.  Is it possible to hide that?  I found one solution online saying to change WindowStyle option in Execute Process Task to hidden but that doesn't work.  The black window still appears.

    Thank you

  • This is nothing to worry about. After deploying your package to a server, no one will be there to see the dialog box during execution.


  • I actually run the SSIS package within VS so I can monitor it for any issues so I am watching those black screens pop up.

  • I don't think there's a way to hide it, so you might have to tolerate it. Or embark on a rewrite.


  • How are you specifying to run PowerShell, as a scripting task? Spitballing here, but could you run it as an Execute Process Task, with powershell.exe as the executable? Then in arguments, "-WindowStyle hidden".

  • dale_berta wrote:

    How are you specifying to run PowerShell, as a scripting task? Spitballing here, but could you run it as an Execute Process Task, with powershell.exe as the executable? Then in arguments, "-WindowStyle hidden".

    Thanks for the suggestion.

    I use Execute Process Task using powershell.exe  as executable  to run PS scripts.

    Without using "-WindowStyle hidden" command, the PS windows stays open and visible until the PS is done.  Not ideal.

    With "-WindowStyle hidden" command, the PS windows opens for less than a second and then gets minimized to the task bar.  This is definitely better than staying open so it is a good improvement.

    Is there a way to flat out stop the PS window from even appearing in the first place?

    Thanks again.

  • You could change the approach to use a script task to execute your powershell script.  However, if you can do this in PS - then you almost certainly can do it using C# in a script task.

    There are some situations where calling out to a PS script needs to be done - if that is the case, then you could do it.  There are examples available, but the general idea is:

    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Diagnostics;
    using System.Linq;
    using System.Management.Automation;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;

    namespace PowerShellScriptExecutor
    {
    class Program
    {
    static void Main(string[] args)
    {
    //Execute PS1(PowerShell script) file
    using (PowerShell PowerShellInst = PowerShell.Create())
    {
    string path = System.IO.Path.GetDirectoryName(@"C:\Temp\") + "\\Get-EventLog.ps1";
    if (!string.IsNullOrEmpty(path))
    PowerShellInst.AddScript(System.IO.File.ReadAllText(path));

    Collection<PSObject> PSOutput = PowerShellInst.Invoke();
    foreach (PSObject obj in PSOutput)
    {
    if (obj != null)
    {
    Console.Write(obj.Properties["EntryType"].Value.ToString() + " - ");
    Console.Write(obj.Properties["Source"].Value.ToString() + " - ");
    Console.WriteLine(obj.Properties["Message"].Value.ToString() + " - ");
    }
    }
    Console.WriteLine("Done");
    Console.Read();
    }
    }
    }
    }

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • Jeffrey Williams wrote:

    You could change the approach to use a script task to execute your powershell script.  However, if you can do this in PS - then you almost certainly can do it using C# in a script task.

    There are some situations where calling out to a PS script needs to be done - if that is the case, then you could do it.  There are examples available, but the general idea is:

    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Diagnostics;
    using System.Linq;
    using System.Management.Automation;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;

    namespace PowerShellScriptExecutor
    {
    class Program
    {
    static void Main(string[] args)
    {
    //Execute PS1(PowerShell script) file
    using (PowerShell PowerShellInst = PowerShell.Create())
    {
    string path = System.IO.Path.GetDirectoryName(@"C:\Temp\") + "\\Get-EventLog.ps1";
    if (!string.IsNullOrEmpty(path))
    PowerShellInst.AddScript(System.IO.File.ReadAllText(path));

    Collection<PSObject> PSOutput = PowerShellInst.Invoke();
    foreach (PSObject obj in PSOutput)
    {
    if (obj != null)
    {
    Console.Write(obj.Properties["EntryType"].Value.ToString() + " - ");
    Console.Write(obj.Properties["Source"].Value.ToString() + " - ");
    Console.WriteLine(obj.Properties["Message"].Value.ToString() + " - ");
    }
    }
    Console.WriteLine("Done");
    Console.Read();
    }
    }
    }
    }

    That is a good idea.  I am an inexperienced c# coder.  I copied and pasted your code into Script Task.  I am getting errors.  How do I fix them?

    Screenshot 2025-02-06 165308

    Thank you

  • That was just an example of how to call out to powershell from C# - and not something specific to an SSIS script task.  You need to make sure you are included the correct references and probably should modify the console statements to specific SSIS code.

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply