Skip to content

Instantly share code, notes, and snippets.

@SegoCode
Last active August 12, 2019 07:34
Show Gist options
  • Save SegoCode/29f9f6d364afeb86dca590cdb2b6f834 to your computer and use it in GitHub Desktop.
Save SegoCode/29f9f6d364afeb86dca590cdb2b6f834 to your computer and use it in GitHub Desktop.
Hide console from powershell script
#----------------------HIDE SCRIPT------------------------------#
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);
'
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
$consolePtr = [Console.Window]::GetConsoleWindow()
[Console.Window]::ShowWindow($consolePtr, 0)
#----------------------------------------------------------------------#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment