If you are running a PowerShell script automatically at startup, login, or as a scheduled task, you may notice the blue console window briefly “flashes” on the screen before disappearing. This happens even when using the standard -WindowStyle Hidden parameter.
This tutorial explains why this happens and provides the most reliable method—using a VBScript wrapper—to ensure your script runs completely invisible.
The Problem: Why -WindowStyle Hidden Still Flashes
PowerShell (powershell.exe) is a console application. When Windows launches a console application, the operating system’s kernel first creates the console window before the application itself starts.
By the time PowerShell reads and executes the -WindowStyle Hidden argument, the window has already been created, causing the brief flicker before the process can hide it.
Solution: The VBScript Wrapper (The Easiest Fix)
The most effective solution to eliminate the window flash is to launch the PowerShell script using a VBScript file. VBScript is run by the Windows Script Host (wscript.exe), which is a Graphical User Interface (GUI) process. A GUI process can spawn another process (like PowerShell) and explicitly tell the OS to launch it as completely hidden, preventing the window from ever appearing.
The Essential Files You Need
We will create two files and place them in a dedicated folder (e.g., C:\Scripts).
| File Name | Extension | Purpose |
MyStartupScript | .ps1 | The actual PowerShell code to run. It uses logging since there’s no visible window. |
RunInvisible | .vbs | The VBScript wrapper that launches the .ps1 file without showing a console window flash. |
1. The PowerShell Script (C:\Scripts\MyStartupScript.ps1)
This sample script creates a log directory and writes a timestamped entry to a log file, confirming it ran successfully.
PowerShell
# MyStartupScript.ps1
# --- Configuration ---
$LogDirectory = "C:\Logs"
$LogFile = "$LogDirectory\StartupScriptLog.txt"
$Date = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
# --- Script Logic ---
# 1. Create the log directory if it doesn't exist
If (-not (Test-Path $LogDirectory)) {
New-Item -Path $LogDirectory -ItemType Directory | Out-Null
}
# 2. Define the log message
$Message = "[$Date] INFO: Startup script successfully executed on $($env:COMPUTERNAME). User: $($env:USERNAME)"
# 3. Write the message to the log file, appending to existing content
$Message | Out-File -FilePath $LogFile -Append -Encoding UTF8
# Optional: Add your actual administrative commands here.
# Example: Restart-Service -Name 'Spooler' -ErrorAction SilentlyContinue
2. The VBScript Wrapper (C:\Scripts\RunInvisible.vbs)
This is the file that will be placed in your Startup location or Task Scheduler, ensuring the PowerShell window never appears.
VB.Net
' RunInvisible.vbs
' This VBScript runs the specified PowerShell script in a completely hidden window.
Set objShell = CreateObject("WScript.Shell")
' *** IMPORTANT: UPDATE THIS PATH TO YOUR ACTUAL SCRIPT LOCATION ***
strScriptPath = "C:\Scripts\MyStartupScript.ps1"
' The full command to execute PowerShell
strCommand = "powershell.exe -NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File """ & strScriptPath & """"
' The 0 at the end means the window is hidden.
' The 'False' means the script doesn't wait for the command to finish.
objShell.Run strCommand, 0, False
Set objShell = Nothing
⚙️ How to Add the Script to Startup (Invisible Method)
Choose one of the following methods to activate your script.
Method A: User Logon (Simplest)
This method runs after a specific user logs in.
- Place Files: Ensure both
MyStartupScript.ps1andRunInvisible.vbsare saved in a location likeC:\Scripts. - Open Startup Folder: Press Win + R, type
shell:startup, and press Enter. - Place the Wrapper: Drag or copy the
RunInvisible.vbsfile into this folder.
The next time that user logs in, the VBScript will execute, silently launching the PowerShell script.
Method B: System Startup (Most Robust)
This method runs when the computer boots, before any user logs in, and guarantees invisibility.
- Open Task Scheduler: Press Win + R, type
taskschd.msc, and press Enter. - Create Task: Click Create Task… on the right side.
- General Tab:
- Name:
Invisible Startup Script - Security Options: Set to SYSTEM (or another non-interactive user).
- Check: Run whether user is logged on or not (Critical for no window).
- Check: Run with highest privileges (Recommended).
- Name:
- Triggers Tab:
- Click New…
- Set Begin the task: to At startup. Click OK.
- Actions Tab (The Key Step):
- Click New…
- Action:
Start a program - Program/script:
wscript.exe - Add arguments (optional): The full path to your VBScript wrapper (e.g.,
C:\Scripts\RunInvisible.vbs).
- Finish: Click OK to save the task.
The next time the computer restarts, the script will execute silently in the background, logging its success to C:\Logs\StartupScriptLog.txt.
🔒 Important Security and Logging Notes
- Check the Log: Since the script is completely invisible, the only way to confirm execution is to check the log file (
C:\Logs\StartupScriptLog.txt). If the log file exists and contains the entry, the script ran successfully. - Execution Policy: Using the VBScript wrapper with the arguments
-ExecutionPolicy Bypassand-NoProfileis the safest way to ensure the script runs without permanently lowering security settings. - Permissions: If your script performs administrative tasks, using Task Scheduler and setting the user to SYSTEM with “Run with highest privileges” is necessary.




