I ran this by a couple of server admins who claimed the AV would not do this, but the security team person I need to work with was out on TTO and when returned it took a while to get them involved. We were able to confirm our AV was not causing this issue.
I upgraded to PSU 3.7.11 and latest PoSh version, but still have the issue. I did further testing to find this only happens when I have a script in C:\ProgramData\UniversalAutomation\Repository\ and when the PowerShellUniversal service is running. I pulled the PSU logs to find this every time I encounter the issue …
2023-03-09 09:45:48.719 -06:00 [WRN] Failed to sync
System.IO.IOException: The process cannot access the file ‘C:\ProgramData\UniversalAutomation\Repository\dashboards\DashboardName\pages\ScriptName.ps1’ because it is being used by another process.
at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
at System.IO.Strategies.OSFileStreamStrategy…ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
at System.IO.Strategies.FileStreamHelpers.ChooseStrategy(FileStream fileStream, String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, Int64 preallocationSize)
at System.IO.File.OpenRead(String path)
at UniversalAutomation.Services.UniversalConfigurationService.SHA256CheckSum(String filePath) in C:\actions-runner_work\universal\universal\src\Universal.Server\Services\UniversalConfigurationService.cs:line 173
at UniversalAutomation.Services.UniversalConfigurationService.ShouldProcess(String fileName, String fullPath) in C:\actions-runner_work\universal\universal\src\Universal.Server\Services\UniversalConfigurationService.cs:line 152
at UniversalAutomation.Services.UniversalConfigurationService.NotifyChange(String fullPath) in C:\actions-runner_work\universal\universal\src\Universal.Server\Services\UniversalConfigurationService.cs:line 116
Afterwards I was researching PSU documentation for something else and came across this Best Practices - PowerShell Universal.
Avoiding Writing to the Repository Directory
The repository directory defaults to
Writing files directly to the repository directory in your scripts can have adverse side effects on performance of the system. PowerShell Universal employs a file system watcher to check for changes to files made on disk. Any changes made within the directory trigger the watcher and configuration file reload verification.
In some instances, writing files can result in configuration reloads that may restart dashboards or cause internal caches to be cleared.
It’s recommended to avoid writing to this directory directly in a default configuration. If you would like to write to the directory, consider disabling the server-wide Auto Reload setting. This will disable the file system watcher and you will no longer risk impacting the configuration of the system.
I enabled the “Disable Auto Reload” setting and the problem went away. I’m concerned with what do I actually lose by disabling the auto reload? It’s rare that I edit or need to restart a dashboard, as I use multi-page dashboards and generally just work on the pages themselves, and they don’t require a dashboard restart. When I do edit a dashboard, I don’t mind restarting it.
I did start having an issue with a Do/Until loop and need to do some further testing to see if disabling auto reload is causing it or not. If the loop gets interrupted in some way refreshing the page, clicking back in the browser, and restarting the dashboard does not stop the loop. The only way I can stop it is to restart the PowerShellUniversal service itself.
Been using PSU for around 3 years now and have always used the default Repository directory, and just now started having this issue with the upgrade to 3.7.10 +. If I need to move the Repository directory, where can I find information on how to do this.