Open o-l-a-v opened 4 weeks ago
From the logs it's hard to say whether module was actually successfully installed. This is another case where feature request #1646 would be useful. 😊
Just tested on my personal computer which worked flawlessly.
This only fails on my work computer were we have CrowdStrike Falcon sensor instead of Windows built in antimalware. I suspect it might have something to do with it, but I don't know for sure.
You could try running handle.exe as administrator to spit out all the open handles and ctrl+f to find what is holding onto the temp file, as long as the handle is still held when you run it then you can see if it's CrowdStrike or powershell or some other thing. You can also use process explorer as administrator and go to "Find -> Find Handle or DLL" to search for which process is holding onto the file or folder.
The time window for when the files are not deletable is so brief, I could not get handle.exe to show anything.
Edit1: What I can see in Task Manager -> Details sorted by CPU usage, is that MsSense.exe
(Windows Defender Advanced Threat Protection Service Executable), SenseNdr.exe
, CSFalconService.exe
and CSFalconContainer.exe
all start working.
Edit 2: With Process Explorer, selecting the MsSense.exe
process, then the Handles tab, I can see that it adds handles to DLLs in temp. Which are still open when Save-PSResource
fails to delete the temp files. Interesting.
Edit 3: Same with CSFalconService.exe
^.
Edit 4: This seems to be the code for deleting a directory. Maybe it can be made more robust in regards to handles from antimalware processes?
I wonder if it would be best to not fail if the temp directory can't be installed, just a verbose message
It seems that PSResourceGet currently does what people in this stackoverflow thread refers to as "nonsense":
Seems many agree that trying multiple times before failing with a small delay is a good idea:
I tried using Dev Drive as -TemporaryPath D:\Temp
for animalware "performance mode" ( https://learn.microsoft.com/en-us/defender-endpoint/microsoft-defender-endpoint-antivirus-performance-mode ), which seems to work fine. But if installing the module twice I get a strange error message:
# Save package with success using Dev Drive as temp
PS > Save-PSResource -Repository 'PSGallery' -TrustRepository -IncludeXml -SkipDependencyCheck -Path $SavePath -Name $ModuleName -TemporaryPath 'D:\Temp'
VERBOSE: Attempting to search for packages in 'PSGallery'
VERBOSE: Installation source path is: 'D:\Temp\685afbd2-002c-4c9d-acce-c5ff2dda6c2f\awspowershell.netcore\4.1.612'
VERBOSE: Installation destination path is: 'C:\Users\olav.birkeland\AppData\Local\Microsoft\PowerShell\Modules\AWSPowerShell.NetCore\4.1.612'
VERBOSE: Temporary module version directory is: 'D:\Temp\685afbd2-002c-4c9d-acce-c5ff2dda6c2f\awspowershell.netcore\4.1.612'
VERBOSE: Attempting to move 'D:\Temp\685afbd2-002c-4c9d-acce-c5ff2dda6c2f\awspowershell.netcore\4.1.612' to 'C:\Users\olav.birkeland\AppData\Local\Microsoft\PowerShell\Modules\AWSPowerShell.NetCore\4.1.612'VERBOSE: Successfully installed package 'AWSPowerShell.NetCore' to location 'C:\Users\olav.birkeland\AppData\Local\Microsoft\PowerShell\Modules'
VERBOSE: Attempting to delete 'D:\Temp\685afbd2-002c-4c9d-acce-c5ff2dda6c2f'
VERBOSE: Successfully deleted 'D:\Temp\685afbd2-002c-4c9d-acce-c5ff2dda6c2f'
# Again, right after last command finished
PS > Save-PSResource -Repository 'PSGallery' -TrustRepository -IncludeXml -SkipDependencyCheck -Path $SavePath -Name $ModuleName -TemporaryPath 'D:\Temp'
VERBOSE: Attempting to search for packages in 'PSGallery'
VERBOSE: Installation source path is: 'D:\Temp\82a3807e-c267-4fed-adde-7ab312444f73\awspowershell.netcore\4.1.612'
VERBOSE: Installation destination path is: 'C:\Users\olav.birkeland\AppData\Local\Microsoft\PowerShell\Modules\AWSPowerShell.NetCore\4.1.612'
VERBOSE: Temporary module version directory is: 'D:\Temp\82a3807e-c267-4fed-adde-7ab312444f73\awspowershell.netcore\4.1.612'
VERBOSE: Attempting to delete with restore on failure.'C:\Users\olav.birkeland\AppData\Local\Microsoft\PowerShell\Modules\AWSPowerShell.NetCore\4.1.612'
Save-PSResource: Unable to successfully install package 'AWSPowerShell.NetCore': 'The process cannot access the file 'C:\Users\olav.birkeland\AppData\Local\Temp\ad0b094f-01e3-4305-be6e-7de0496d382b\AWSSDK.CloudFormation.dll' because it is being used by another process.'
Save-PSResource: Operation is not valid due to the current state of the object.
VERBOSE: Attempting to delete 'D:\Temp\82a3807e-c267-4fed-adde-7ab312444f73'
VERBOSE: Successfully deleted 'D:\Temp\82a3807e-c267-4fed-adde-7ab312444f73'
Save-PSResource: Package(s) 'AWSPowerShell.NetCore' could not be installed from repository 'PSGallery'.
PS >
The directory in the error message does not exist, I've made sure of it. Seems the error throws when deleting the module which will be overriden, it was just installed and antimalware is probably still scanning all the content and placing file handles. But it is not located in %TEMP%
.
Prerequisites
Steps to reproduce
Lately PSResourceGet has had problems installing AWSPowerShell.NetCore on my system. I use
Save-PSResource
because I want modules in user context, but not synced with OneDrive (Known Folder Move).It seems that the installation succeeds, as in it managed to move all files to
-Path
. But then it fails at deleting the temp directory used for downloading and extracting the files.If a service like an antimalware scan is the reason these files can't be deleted: Detect it and wait for it to finish? Or try twice, wait five seconds before second attempt?
Expected behavior
PSResourceGet should succeed in deleting temp path.
Actual behavior
PSResourceGet fails to delete temp path.
Error details
Environment data
Visuals
No response