Skip to content

Conversation

@AmonReviled
Copy link

@AmonReviled AmonReviled commented Jan 3, 2026

This PR fixes issue #264 where PowerShell sensors and commands fail when users have custom profile scripts (e.g., Starship terminal prompt).

Problem

When executing PowerShell commands or scripts, HASS.Agent was not using the -NoProfile flag. This caused custom profile scripts (like Microsoft.PowerShell_profile.ps1) to be loaded, which could:

  • Append error messages to the sensor output
  • Cause "Cannot run script on machine" errors
  • Include unwanted output from profile initialization
image

Solution

Added -NoProfile flag to all PowerShell executions in PowershellManager.cs:

  1. GetProcessArguments method - Used by ExecuteHeadless and Execute:

    • Script: -NoProfile -File "{command}"
    • Command: -NoProfile -EncodedCommand {encodedCommand}
  2. ExecuteWithOutput method - Used by sensors for testing:

    • Script: -NoProfile & '{command}'
    • Command: -NoProfile & {{{command}}}

The -NoProfile flag tells PowerShell to skip loading any profile scripts, ensuring clean and predictable execution.

Closes #264

@AmonReviled AmonReviled force-pushed the fix-powershell-noprofile branch from 2e6a04d to c097d96 Compare January 3, 2026 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: "Cannot run script on machine" error when trying to run Powershrll scripts with a custom profile script.

2 participants