Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Remote Move-Item Problem

$
0
0

Not sure if this is posted in the right forum or not, but it does deal with a remote job.

My problem is that I run a cleanup task against multiple servers and move the files to a somewhat temporary location. The Move statement has an error. I'm not exactly sure how to change it since it seems to be working. It looks just to be like an "Open file error" or I might just not be looking at the statement correctly. Could someone explain it further for me please.  Below is the statement line and output.


1  $Serverlist = Get-Content -path C:\CENT\Servers\Servers.txt 
2  foreach ($computer in $Serverlist)
3  {
4   tree \\$Computer\d$ /A /F > "C:\CENT\Servers\TREE_Before\$Computer.txt"
5   $MAINDIR = "\\$computer\d$\*"
6   $TARGETDIR = "\\$computer\d$\2BREMOVED"
7   $MAINDIR
8   $TARGETDIR
9   if(!(Test-Path -Path $TARGETDIR ))
10 # PrePend UNC Test statement like so If the Test gets Flakey
11 #  (EX:  Test-Path -Path FileSystem::\\127.0.0.1\c$)
12     {
13       New-Item -Type directory -Path $TARGETDIR
14  Get-item $MAINDIR -exclude Apps,Group, Home,'Standard Edition' | Move-Item -Destination $TARGETDIR
15  tree \\$Computer\d$ /A /F > "C:\CENTServers\TREE_After\$Computer.txt"
16  write-host " $computer Done"
17   }
18 }

*******************************************************************************************
output:
\\Server01\d$\*
\\Server01\d$\2BREMOVED


    Directory: \\Server01\d$


Mode                LastWriteTime     Length Name                                                                 
----                -------------     ------ ----                                                                 
d----         9/17/2014   3:54 AM            2BREMOVED                                                            
Move-Item : The process cannot access the file because it is being used by another process.
At C:\~.ps1:14 char:66
+ ... tion Server' | Move-Item -Destination $TARGETDIR
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (\\Server01\d$\2BREMOVED:DirectoryInfo) [Move-Item], IOException
    + FullyQualifiedErrorId : MoveDirectoryItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand
 
 Server01 Done


Viewing all articles
Browse latest Browse all 6937

Trending Articles