| According to this article, Powershell is unable to fully unload a previously loaded DLL. The only way to unload a DLL is to end the Powershell session. This presents a problem to Bolt as it executes (Powershell-based) Bolt Tasks in-process when connecting via WinRM. As a result, if the Bolt Task loads a Powershell module that contains a DLL during execution, that module's DLL stays loaded after the Tasks completes. This will cause Bolt's cleanup phase to show these errors is the debug log:
Executing command: Remove-Item -Force -Recurse -Path "C:\Users\Administrator\AppData\Local\Temp\chjzt3c5.ot3" |
|
stdout: |
stderr: Access to the path 'PSWindowsUpdate.dll' is denied. |
At line:1 char:1 |
+ Remove-Item -Force -Recurse -Path "C:\Users\Administrator\AppData\Loc ... |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
+ CategoryInfo : PermissionDenied: (PSWindowsUpdate.dll:FileInfo) [Remove-Item], UnauthorizedAccessException |
+ FullyQualifiedErrorId : RemoveFileSystemItemUnAuthorizedAccess,Microsoft.PowerShell.Commands.RemoveItemCommand |
|
stdout: |
stderr: The directory is not empty.At line:1 char:1 |
+ Remove-Item -Force -Recurse -Path "C:\Users\Administrator\AppData\Loc ... |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
+ CategoryInfo : WriteError: (files:DirectoryInfo) [Remove-Item], IOException |
+ FullyQualifiedErrorId : RemoveFileSystemItemIOError,Microsoft.PowerShell.Commands.RemoveItemCommand |
|
stdout: |
stderr: The directory is not empty.At line:1 char:1 |
+ Remove-Item -Force -Recurse -Path "C:\Users\Administrator\AppData\Loc ... |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
+ CategoryInfo : WriteError: (windows_updates:DirectoryInfo) [Remove-Item], IOException |
+ FullyQualifiedErrorId : RemoveFileSystemItemIOError,Microsoft.PowerShell.Commands.RemoveItemCommand |
|
stdout: |
stderr: The directory is not empty.At line:1 char:1 |
+ Remove-Item -Force -Recurse -Path "C:\Users\Administrator\AppData\Loc ... |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
+ CategoryInfo : WriteError: (C:\Users\Admini...mp\chjzt3c5.ot3:DirectoryInfo) [Remove-Item], IOException |
+ FullyQualifiedErrorId : RemoveFileSystemItemIOError,Microsoft.PowerShell.Commands.RemoveItemCommand |
|
Command failed with exit code 5 |
Closed session |
When checking the remote node, we can confirm that the temp directory has not been removed and the offending DLL is still remaining in it. To mitigate this problem, Bolt should execute Powershell-based commands & Tasks in a new Powershell session, instead of its own session. That way, the child session will end after execution, causing the DLL to be unloaded. When the parent session then performs the cleanup, no access-denied issues will occur. Running user content (commands/Tasks) in a separate process is also likely to be more robust as the parent process will remain unaffected by anything unexpected happening in the child process. |