Skip to content

[Bug]: Windows uninstall script fails in Windows PowerShell 5.1 due to UTF-8 without BOM / Unicode characters #769

@MicEs1

Description

@MicEs1

What is the installation method of your PatchMon server?

Proxmox-community script

What is the version of your PatchMon server?

2.0.2

Affected OS:

Windows Server / Windows Client
PowerShell: Windows PowerShell 5.1 / powershell.exe

Description:

The Windows agent uninstall command generated by the PatchMon GUI downloads a PowerShell script from:

/api/v1/hosts/remove?os=windows

The downloaded script fails with parser errors when executed via Windows PowerShell 5.1. The issue appears to be caused by the script being saved as UTF-8 without BOM while containing emojis / Unicode characters in Write-Host output.

Windows PowerShell 5.1 may interpret such files as ANSI/Windows-1252, which corrupts Unicode byte sequences and leads to invalid PowerShell syntax.

Steps to reproduce

  1. Install the Windows agent using the generated install command from PatchMon 2.0.2.
  2. Copy the Windows uninstall command from the PatchMon GUI.
  3. Download and run the generated removal script:
    powershell.exe -ExecutionPolicy Bypass -File "$env:TEMP\patchmon-remove.ps1"

Expected behavior

The script should run successfully and uninstall the Windows agent.

Actual behavior:

The script fails with parser errors similar to:

  • Unexpected token "}" in expression or statement.
  • The string is missing the terminator: '.
  • The Try statement is missing its Catch or Finally block.

Additional context

Example errors:

C:\Users<user>\AppData\Local\Temp\patchmon-remove.ps1:81 char:9
Unexpected token "}" in expression or statement.

C:\Users<user>\AppData\Local\Temp\patchmon-remove.ps1:168 char:93
The string is missing the terminator: '.

  • The Linux agent uninstall works correctly.
  • The problem seems specific to the generated Windows removal script.

Workaround:

Removing the emojis / Unicode symbols from the script output makes the script run successfully.

Saving the script as UTF-8 with BOM may also help, but the safer fix would probably be to avoid emojis / non-ASCII characters in Windows PowerShell scripts generated for powershell.exe compatibility.

Suggested fixes:

  • Generate the Windows uninstall script as UTF-8 with BOM, or
  • remove emojis / non-ASCII characters from generated Windows PowerShell scripts, or
  • use PowerShell 7 compatible execution instructions explicitly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions