Welcome › Forums › General PowerShell Q&A › When mapping to network drive I get an error when retrieving files(not always)
- This topic has 1 reply, 1 voice, and was last updated 9 months ago by
Participant.
-
AuthorPosts
-
-
April 25, 2020 at 4:09 pm #222453
Hi,
I am mapping a network drive in Powershell, but have some weird behavior when retrieving files from the drive. Sometimes it works most of the time it doesn’t. I have two locations, one lets say from GIT and the other one is my network drive I am creating. I want to compare the files from both locations and see if there is a difference between them. Let me explain what I am doing in the code:
PowerShell12345$somePath = "\\testtest.lan\Res\Application\TestApp\SomeFiles"$PsDrive = New-PSDrive -Name "M" -PSProvider "FileSystem" -Root $somePathI also tried : $PsDrive = New-PSDrive -Name "M" -PSProvider "FileSystem" -Root $somePath -Persist -Scope GlobalNext, I am trying to get all the files from my network drive and here the problem happens:
PowerShell1$someVariable= Get-ChildItem "M:\" -Recurse | Select-Object -Property *, @{n='Path';e={$_.FullName -replace [regex]::Escape("M:\")}}Here I am facing some strange behavior, sometimes it returns all the child items as it should, but most of the time I get an error saying: “Get-ChildItem : An unexpected network error occurred.” or couple of times it happened to give me this error and nothing more :
PowerShell1234At line:1 char:1+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo : ReadError: (M:\:String) [Get-ChildItem], IOException+ FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommandWhen I do Get-PsDrive I can see the mapped drive there.
Do you guys think I am doing something wrong in the code or some problem with the network location I am trying to access. It shouldn’t be related to permissions since there are times when it’s working correctly. Is it possible to see a more detailed or accurate error message?
Last but not least, sorry If I didn’t followed some forum rules, I am new here. Will try to improve in my next post. 🙂
Thanks,
Chichak
-
April 27, 2020 at 4:28 pm #222942
That appears to just be a generic network error, so it could be many things. As it’s sporadic, it’s even more of a pain to troubleshoot root cause. Maybe create a loop to try to get files 3 times to attempt to get the files with a 15 sec sleep or something. Personally have spent many many hours trying to root cause something like this, but scripting around it is a bandaid. You’d have to look at all of touchpoints, DFS, NFS, Windows, etc. to try get logs locally on your client and touchpoints.
-
-
AuthorPosts
- The topic ‘When mapping to network drive I get an error when retrieving files(not always)’ is closed to new replies.