Out-file refreshes/crashes the dashboard

Product: PowerShell Universal
Version: 3.7.10

I wanted to write error logs to a file, so I have some try/catch blocks where I use the out-file command in catch, but every time this command is called the dashboard reloads (maybe crashes).

In the code below, I added “UnknownCommandToForceCrash” to force the catch, and then the dashboard restarts, not sure why?

Hope someone can help :slight_smile:

Show-UDModal -Content {
    New-UDTypography -Text "Are you sure?"
} -Footer {
    New-UDButton -Text "Yes" -OnClick {
        try {
            # When confirmed, do something
            Show-UDToast -Message "Success!" -BackgroundColor "#4CAF50" -Duration 8000
        } catch {
            Show-UDToast -Message "FAILED!" -BackgroundColor "#FF0000" -Duration 8000
            "$(get-date) " + "Resetpwdbtn$($EventData.SamAccountName) " + $_ + $body | Out-File .\dashboards\Tools\LogFiles\LOG.txt -Append
            # ^?Restarts the dashboard?^
        } finally {
    } -Style @{"border-radius" = "4px"}
    New-UDButton -Text "No" -OnClick { Hide-UDModal } -Style @{"border-radius" = "4px"}
} -Persistent

It’s because you are writing to the dashboard folder. Anything under that folder will cause an auto-reload if auto-deploy is enabled for that dashboard.

Ah ye, of course. Thanks! :smiley: