2017-07-27 67 views
1

我需要从回收站中恢复超过40000个项目,通过GUI它使用了大量内存,系统几乎挂起,即使我在100个项目时间。因此,我在PowerShell中写了下面的脚本,但我有以下错误:

VERBOSE: Performing the operation "Move Directory" on target "Item: E:\$RECYCLE.BIN\S-1-5-21-45987200-1508583899-68119131-500\$R2FXY9E Destination: E:\OneDrive - MHG - Brasil\Admin_Fin\Silvia\Silvia\Clientes\Miller Heiman Group\Embraer\Fase I\ARIBA\Embraer - Evento - Resumo_arquivos". 
Move-Item : Could not find a part of the path. 
At E:\Scripts\ListaRecycled.ps1:7 char:6 
+  Move-Item $item.Path $CaminhoCompleto -Force -Verbose 
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : WriteError: (E:\$RECYCLE.BIN...31-500\$R2FXY9E:DirectoryInfo) [Move-Item], 
DirectoryNotFoundException 
    + FullyQualifiedErrorId : MoveDirectoryItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand 

在我的代码,我做了以下内容:

$Shell = New-Object -ComObject Shell.Application 
$Global:Recycler = $Shell.NameSpace(0xa) 
$Excluidos = $Recycler.Items() 
foreach ($item in $Excluidos) 
{ 
    $CaminhoCompleto = Join-Path $Recycler.GetDetailsOf($item,1) $Recycler.GetDetailsOf($item,0) 
    Move-Item $item.Path $CaminhoCompleto -Force -Verbose 
} 

感谢。

+0

我认为您的箱子中有一个空白对象或者名称不正确。我上面试过你的代码,事实证明我有一个没有名字的文件夹(不知道它来自哪里),但是因为连接路径函数的运行方式而崩溃了。它找到了旧的路径,试图连接一个空白名称,然后试图将其移到基础文件夹。不知道这是否也是您的问题,但值得检查垃圾箱的内容以确保您没有任何空白。 –

+0

您可以使用该项目的属性来确定目的地。 '$ item.getfolder.title' – TheMadTechnician

回答

2

您正在使用位置参数,未命名。 Move-Item将位置0处的参数作为参数Path,该参数受壳shell匹配的影响。

无论如何,您通常应该使用命名参数,在这种情况下,您确实需要使用-LiteralPath而不是-Path

Move-Item -LiteralPath $item.Path -DestinationPath $CaminhoCompleto -Force -Verbose 
0

我发现了。该Move-Item cmdlet不创建一个文件夹路径,因此,我就加我的脚本如下:

if(!(Test-Path $Recycler.GetDetailsOf($item,1))) 
{ 
    New-Item -Path $Recycler.GetDetailsOf($item,1) -ItemType Directory -Force -Verbose -OutVariable +Dir 

} 

我发现太那个失踪的项目DACL。然后我添加了以下内容:

$permissoes = Get-Acl $item.Path -Verbose 
Move-Item -LiteralPath $item.Path -Destination $CaminhoCompleto -Verbose -ErrorVariable +Err  
Set-Acl -Path $CaminhoCompleto -AclObject $permissoes -Verbose