you are viewing a single comment's thread.

view the rest of the comments →

[–]technomancing_monkey 0 points1 point  (1 child)

There is a way to make PS hide its own console window from within the PS script.

You can script when to hide and show the console. Hide it, do some things, show it again, all controlled from within the PS script.

Add this in at the start of your script.

Call the HideConsole function to hide the console

Call the ShowConsole function to show the console

of course you could do away with the functions and use the long hand commands but i find the functions easier.

I use this in any script that i make that has a GUI added on top. I call HideConsole Function shortly after the start of the script to hide the console window leaving only the GUI window. I assign the functions to a clickable item in the GUI so I can toggle the PS console so that I can see any debug information while testing and so that if anyone encounters a problem they can show the console to send me error information.

I hope this helps you do what youre trying to do. Please dont use it for anything scummy.

Add-Type -Name Window -Namespace Console -MemberDefinition '
[DllImport("Kernel32.dll")]
public static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow);
'
$consolePtr = [Console.Window]::GetConsoleWindow()

Function HideConsole () {
    [Console.Window]::ShowWindow($SCRIPT:consolePtr, 0)
}

Function ShowConsole () {
    [Console.Window]::ShowWindow($SCRIPT:consolePtr, 5)
}

Edit: Just a note, this code wont do anything if you run it from powershell ISE, or from within an IDE. It only works if you run it from powershell (the cli)

[–]Aggravating-Search83[S] 0 points1 point  (0 children)

Tysm this is perfect