November 25, 2024 at 5:43 am
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
November 25, 2024 at 9:11 am
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.
November 25, 2024 at 4:19 pm
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.
November 25, 2024 at 4:35 pm
I don't think there's a way to hide it, so you might have to tolerate it. Or embark on a rewrite.
December 4, 2024 at 1:43 pm
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".
February 6, 2025 at 6:12 am
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.
February 6, 2025 at 10:12 pm
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
February 7, 2025 at 12:54 am
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?
Thank you
February 7, 2025 at 7:23 pm
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
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy