> ## Content Index
> Fetch the complete content index at: https://blog.sudowl.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# A PowerShell Window Opened at Every Login. Here's How I Traced It (and Audited All of Startup)
- URL: https://blog.sudowl.com/powershell-window-at-every-login-find-startup-source/
- Published: 2026-12-01T10:00:00.000Z
- Updated: 2026-12-04T12:22:14.000Z
- Description: A blank PowerShell window popped up at every login. Tracing it via parent processes to a scheduled task, then a full Windows startup audit and cleanup.
- Author: Lukas
- Tags: Windows Server

Every time I started my PC, a PowerShell window opened. Just a console sitting there. Close it and something I needed would break. That's worth chasing down, because "random console at login" is also what you'd see if something nasty had set up shop.

It turned out to be harmless and self-inflicted. But finding it was a nice little exercise in process forensics, and once I was in there I audited the whole startup chain. That part was the bigger win.

**TL;DR:** List `powershell.exe` and `conhost.exe` with their command line and parent PID via `Get-CimInstance Win32_Process`. Walk the parents up. If the parent is a `svchost.exe` running the Task Scheduler service, it's a scheduled task. Mine was a logon task looping an `rclone mount`. `-WindowStyle Hidden` didn't hide it because Windows Terminal is my default console. Then audit Run keys, `StartupApproved`, startup folders, non-Microsoft logon tasks and auto-start services. Expect leftovers.

## Step 1: who is that window?

```powershell
Get-CimInstance Win32_Process -Filter "Name='powershell.exe' OR Name='conhost.exe'" |
  Select-Object ProcessId, ParentProcessId, CreationDate, CommandLine |
  Sort-Object CreationDate

```

`Get-Process` in Windows PowerShell 5.1 doesn't give you parent PID or full command line. `Win32_Process` does. Sorting by `CreationDate` groups the login burst together.

Shortened, my output looked like this:

```text
ProcessId       : 11956
ParentProcessId : 2612
CreationDate    : 11/30/2026 6:57:33 PM
CommandLine     : "powershell.exe" -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File "C:\Users\me\drive-mount.ps1"

ProcessId       : 13096
ParentProcessId : 1868
CreationDate    : 11/30/2026 6:57:34 PM
CommandLine     : "...\WindowsTerminal.exe" -Embedding

```

Two things jump out. A PowerShell running a `.ps1` from my profile folder, started at login. And one second later, Windows Terminal getting started with `-Embedding`, which is what you see when it's launched to host a console for someone else rather than by me clicking on it.

The other `conhost.exe` processes belonged to services (a database server, GPU and graphics driver services). Normal, nobody sees those.

## Step 2: walk the parents

```powershell
Get-CimInstance Win32_Process -Filter "ProcessId=2612" |
  Select-Object ProcessId, Name, ParentProcessId, CommandLine

# which service lives in that svchost?
Get-CimInstance Win32_Service -Filter "ProcessId=2612" | Select-Object Name, DisplayName

```

Parent was `svchost.exe`, which alone tells you little. The second query tells you which service lives in it. If it says `Schedule`, you're looking at a scheduled task.

Then find the task by what it runs:

```powershell
Get-ScheduledTask | Where-Object { $_.Actions.Arguments -match 'drive-mount' } |
  Select-Object TaskName, TaskPath, State

$t = Get-ScheduledTask -TaskName 'Drive Z'
$t.Actions   | Select-Object Execute, Arguments
$t.Principal | Select-Object UserId, RunLevel, LogonType
$t.Triggers

```

There it was. A task in the root folder, state `Running`, logon trigger, `LogonType : Interactive`, `RunLevel : Limited`. I had built it myself a while ago for a drive I had set up for a client's storage box. The script:

```powershell
while ($true) {
  if (-not (Test-Path 'Z:\')) {
    & rclone.exe mount remote:Data Z: --vfs-cache-mode full --vfs-cache-max-size 20G `
      --dir-cache-time 30s --network-mode --volname "Data" `
      --log-file "$env:LOCALAPPDATA\rclone-mount.log" --log-level NOTICE
  }
  Start-Sleep 60
}

```

Endless loop, checks every 60 seconds whether `Z:` exists, and if not, mounts it. `rclone mount` blocks for as long as the mount lives, so in practice the loop only goes round again if the mount dies. As a "keep my drive mounted" watchdog that's fine. As something that owns a visible console window, it's terrible, because closing the window kills the mount.

## Gotcha: -WindowStyle Hidden doesn't hide it with Windows Terminal as default

The task already had `-WindowStyle Hidden`. Didn't matter. On Windows 11 with Windows Terminal set as the default terminal application, the console gets handed to Terminal, and the hidden window style doesn't reliably survive that. You get a Terminal window with your "hidden" script in it. That's what the `WindowsTerminal.exe -Embedding` one second later was.

The fix I applied first was to start PowerShell through a headless conhost, so no console window gets created for Terminal to grab:

```powershell
$a = New-ScheduledTaskAction -Execute 'conhost.exe' `
  -Argument '--headless powershell.exe -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File "C:\Users\me\drive-mount.ps1"'
Set-ScheduledTask -TaskName 'Drive Z' -Action $a

```

Honest disclaimer: I never verified this after a reboot. Before the next restart I decided the drive didn't belong on this PC at all anymore, and removed the whole thing. So treat `conhost.exe --headless` as the known workaround, not something I've watched work on my machine.

## Step 3: remove it properly

If the thing shouldn't be there, kill it completely. Not just the task.

```powershell
Stop-ScheduledTask -TaskName 'Drive Z'
Unregister-ScheduledTask -TaskName 'Drive Z' -Confirm:$false
Get-Process rclone -ErrorAction SilentlyContinue | Stop-Process -Force
Remove-Item "C:\Users\me\drive-mount.ps1"

rclone config delete remote

```

The last line matters most. The rclone remote was an SFTP config with the credentials for someone else's storage. rclone only obscures passwords in `rclone.conf`, it doesn't encrypt them unless you set a config password. A forgotten remote is a credential lying around on your disk. Then check:

```powershell
"Task: $([bool](Get-ScheduledTask -TaskName 'Drive Z' -ErrorAction SilentlyContinue))"
"Z: $(Test-Path 'Z:\')"
"Proc: $(@(Get-Process rclone -ErrorAction SilentlyContinue).Count)"
rclone listremotes

```

`Task: False`, `Z: False`, `Proc: 0`. Done. Nothing changed on the storage side, the client's own sync kept running.

## Step 4: audit everything else that starts

The window was the visible symptom. What else runs that I don't see?

```powershell
$run = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Run',
       'HKLM:\Software\Microsoft\Windows\CurrentVersion\Run',
       'HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Run'
foreach ($p in $run) {
  $k = Get-ItemProperty $p -ErrorAction SilentlyContinue
  if ($k) {
    $k.PSObject.Properties | Where-Object Name -notlike 'PS*' |
      ForEach-Object { "[$p] $($_.Name) = $($_.Value)" }
  }
}

```

A Run entry existing doesn't mean it runs. When you disable something in Task Manager's Startup tab, Windows doesn't delete the Run value. It writes a flag into a parallel `StartupApproved` key:

```powershell
$sa = 'Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved'
foreach ($hive in 'HKCU:', 'HKLM:') {
  foreach ($sub in 'Run', 'Run32', 'StartupFolder') {
    $k = Get-ItemProperty "$hive\$sa\$sub" -ErrorAction SilentlyContinue
    if (-not $k) { continue }
    $k.PSObject.Properties | Where-Object Name -notlike 'PS*' | ForEach-Object {
      $state = if ($_.Value[0] -in 2, 6) { 'on' } else { 'OFF' }
      "$sub $($_.Name): $state"
    }
  }
}

```

First byte 2 or 6 means enabled, anything else means it was switched off. No entry at all means enabled. `Run32` covers the WOW6432Node key, `StartupFolder` covers shortcuts.

The other three places:

```powershell
# startup folders
Get-ChildItem "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Startup",
              "$env:ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp"

# logon/boot tasks that aren't Microsoft's
Get-ScheduledTask | Where-Object {
  $_.TaskPath -notlike '\Microsoft\*' -and
  ($_.Triggers.CimClass.CimClassName -match 'Logon|Boot')
} | Select-Object TaskPath, TaskName, State

# auto-start services outside the Windows folder
Get-CimInstance Win32_Service -Filter "StartMode='Auto'" |
  Where-Object PathName -notmatch '\\Windows\\' |
  Select-Object Name, State, PathName

```

## What I found

- **The drive task was the only thing with a visible window.** Good.
- **Most Run entries were already disabled** in Task Manager. Launchers, chat, notes, Docker, sync clients. I'd done that earlier.
- **Dead leftovers.** Run entries for apps that were long uninstalled: an old game, two Android emulators, a game client. Plus two junk `AF_*` entries, one of them full of binary garbage. All disabled, all pointless.
- **My own tool was registered twice**, once in HKCU and once in HKLM. So it could start twice at every login. My bug.
- **A cloud sync client was "off" in autostart but started anyway**, through its own scheduled task. Task Manager doesn't show you that.
- **Five VPN programs installed.** Three of them free VPN apps I don't trust, one still running as a service. Plus a browser "safety" add-on of the kind that usually rides in with another installer.

## Cleanup and its gotchas

Two of the free VPNs were Store apps.

```powershell
Get-AppxPackage VendorA.VpnOne, VendorA.VpnTwo | Remove-AppxPackage

```

```text
Get-AppxPackage : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'Name'.

```

## Gotcha: Get-AppxPackage -Name takes one string

`-Name` isn't an array parameter, but it takes wildcards. Both apps shared a publisher prefix, so:

```powershell
Get-AppxPackage 'VendorA.*' | Remove-AppxPackage

```

## Gotcha: Store app removed, Windows service stays

After the uninstall, both apps' Windows services were still registered with `StartMode Auto`. One was stopped, the other was still **running**, pointing at an exe under `C:\Program Files\WindowsApps\` that no longer existed. Uninstall didn't clean them up, so I did, from an elevated shell:

```powershell
Stop-Service VpnOneService -Force
sc.exe delete VpnOneService
sc.exe delete VpnTwoService

```

Use `sc.exe`, not `sc`. In PowerShell, `sc` is an alias for `Set-Content`.

## Gotcha: MSI uninstall from a non-admin shell

The third VPN and the browser add-on were classic installers. My shell wasn't elevated (`Admin: False`), so I looked up the uninstall strings and ran them through a UAC prompt:

```powershell
Get-ItemProperty 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*',
                 'HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' |
  Where-Object DisplayName -like '*VPN*' |
  Select-Object DisplayName, UninstallString, QuietUninstallString

Start-Process msiexec.exe -ArgumentList '/x {00000000-0000-0000-0000-000000000000} /qn' -Verb RunAs -Wait -PassThru |
  ForEach-Object ExitCode

```

The VPN showed up twice with two different uninstall strings for the same product GUID. Doesn't matter, `msiexec /x` with the GUID is the one that counts. Exit code 0 for both. Deleting the HKLM Run values went in the same elevated script.

## End state

Three free VPNs and the add-on gone, including their orphaned services. My own tool registered once, machine-wide only. Dead Run entries deleted. The other two VPNs and a gaming network tool stayed. The cloud sync task and the hardware vendor's tasks I left alone on purpose. No reboot needed.

More digging basics: [PowerShell sysadmin cheatsheet](/powershell-sysadmin-cheatsheet/) and [Task Scheduler + PowerShell automation](/windows-task-scheduler-powershell-automation/). The drive setup itself: [Storage Box as a Windows network drive](/windows-storage-box-network-drive/) and [rclone bisync on Windows](/rclone-bisync-windows-desktop-storage-box/).

Lesson: a visible window at login is a gift. It's the invisible stuff that piles up.

---

### Related posts

- [Printing a Website on A3: The PDF Was Right, the Print Came Out A4](https://blog.sudowl.com/print-website-a3-pdf-prints-as-a4/)
- [Two-Way Syncing a Windows Desktop to a Storage Box with rclone bisync and Task Scheduler](https://blog.sudowl.com/rclone-bisync-windows-desktop-storage-box/)
- [Microsoft 365 Expired? Rescuing a Mailbox from the Local OST into a PST](https://blog.sudowl.com/export-m365-mailbox-ost-to-pst/)