Skip to content

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

@Barina

Description

@Barina

Describe the bug
I'm using a custom profile script for my powershell (for Starship mainly) but looks like HASS.agent doesn't like this.
I've created a sensor script that outputs a state On\Off based on something and made HASS run it as "Powershell command or script" in the sensors window.
But whenever there's a custom profile script (at "D:\Roy\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1" for me) the output includes (appended to the desired output) an error stating scripts are disabled on this machine. see screenshot below..
I don't know how HASS is calling PS behind the scenes but maybe adding the -NoProfile argument is all we need..

To Reproduce

  1. in HASS GUI, got to "Sensors"
  2. create a new sensor with the following configuration:
    • Type: PowershellSensor
    • powershell command or script: echo "Hello World"
  3. now click on the test button
  4. observe the popup, it should say Test successfully executed, result value: Hello World
  5. dismiss the popup
  6. now create the file <Documents-Path>\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 with any content, for me it's:
$env:STARSHIP_CONFIG = "$HOME\.config\starship\starship.toml"
Invoke-Expression (&starship init powershell)
  1. go back to HASS sensors window and click the test button again
  2. observe the result popup, it should say the same as before but now also includes a pipe and an error message

Expected behavior
HASS shouldn't use PS profiles and not attach the error to the output\payload. instead the error should be logged

Screenshots
Image

Misc info (please complete the following information):

  • Windows build (ideally screenshot/info of winver.exe output):

Image

  • Windows' UI language: enUS
  • HASS.Agent version: 2.1.1

Please check what's applicable (multiple answers possible):

  • Installed via installer
  • Installed manually
  • Problem occurs in HASS.Agent
  • Problem occurs in Satellite Service

Additional context
I only tested a custom profile script to add Starship to my terminal but maybe this issue will persist whenever the script exist. you should test that before installing Starship :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageMore information is required / ongoing investigation

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions