Oh goody a puzzle
So what is the PowerShell version? This is all a little strange. I have never heard of files staying open once the process that opened them terminates.
Are you certain the process terminates?
Copy-Item copying folder and files but files are locked
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- Alexander Riedel
- Posts: 8488
- Last visit: Tue Apr 16, 2024 8:42 am
- Been upvoted: 37 times
Re: Copy-Item copying folder and files but files are locked
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
-
- Posts: 9
- Last visit: Wed Jun 07, 2023 1:12 pm
Re: Copy-Item copying folder and files but files are locked
PowerShell version installed on my machine is: 5.1.19041.1682
The Copy-Item command seems to finish since the rest of the script is run successfully (other than not renaming the folders that have files in them). It seems that Copy-Item is a blocking command so it would have to finish before the rest of the script is run, correct?
The form window is closed after all of the script functions are complete so that should close all related processes, right?
When I check running processes in Task Manager I don't see anything that seems to be related to my script. Unless it could be called something unrelated.
The Copy-Item command seems to finish since the rest of the script is run successfully (other than not renaming the folders that have files in them). It seems that Copy-Item is a blocking command so it would have to finish before the rest of the script is run, correct?
The form window is closed after all of the script functions are complete so that should close all related processes, right?
When I check running processes in Task Manager I don't see anything that seems to be related to my script. Unless it could be called something unrelated.
Re: Copy-Item copying folder and files but files are locked
If the share is part of a replication set then this can happen on busy networks.
I would start by restarting the server as things can get out of sync. The network techs should be advised as to this condition as they would know more about the configuration of the servers and any replication that may be defined.
You can temporarily turn on detailed file logging to see what is causing the locks.
I would start by restarting the server as things can get out of sync. The network techs should be advised as to this condition as they would know more about the configuration of the servers and any replication that may be defined.
You can temporarily turn on detailed file logging to see what is causing the locks.
-
- Posts: 9
- Last visit: Wed Jun 07, 2023 1:12 pm
Re: Copy-Item copying folder and files but files are locked
Thanks for the recommendation, and I thought about that as well.
We do use DFS replication (I set up the severs), but that doesn't explain why it only happens when running the script from the .exe and not the .ps1. I have also tested it on a server with no replication and the outcome is the same -- the .ps1 version works fine, but the .exe results in open files.
Re: Copy-Item copying folder and files but files are locked
Logging open handles for the folder and files would be the best way to proceed. This will tell you what process has opened and locked the files.
Re: Copy-Item copying folder and files but files are locked
My suggestion is to use any of the sync/copy tools that have the ability to copy open/locked files/ in-use files/real-time files like Goodsync and Gs Richcopy360 , both are easy and quick