2012-11-13 36 views
5

我是新来的powershell,并且在递归拷贝期间尝试排除某些目录时遇到问题。任何帮助表示赞赏! 在此先感谢。powershell - 在递归拷贝期间无法排除文件夹

$Date = Get-Date 
$Date = $Date.adddays(-1) 

$destPath = "\\destination\test" 
$srcPath = "H:\program files\symphony\Save" 
$srcPathRemits = “H:\program files\symphony\files" 
$destDrive = "X:" 
$User = "user" 
$Password = "password" 

$exclude = @('H:\program files\symphony\files\Temp\*','H:\program files\symphony\files\Other\*','H:\program files\symphony\files\etc\*','H:\program files\symphony\files\ParsedXML\*') 

$net = new-object -ComObject WScript.Network 
$net.MapNetworkDrive($destDrive, $destPath, $false, $User, $Password) 

gci -recurse -path $srcPathRemits -Exclude $exclude | ? {!($_.psiscontainer) -AND $_.lastwritetime -gt $Date} | % { write-host $_.fullname; Copy-Item -path $_.fullname -destination $destDrive} 
$net.RemoveNetworkDrive($destDrive,"true","true") 
+1

当你说你遇到了问题,你能更具体吗?你收到错误信息了吗?它以前如何? – David

+0

请记下你有机会时回答的问题。谢谢。 – David

回答

9

你没有说的问题是什么,但我会假设目录($exclude)没有正确排除。试试这个,对于gci行:

Get-Item -Path H:\program files\symphony\files\* -Exclude Temp, Other, etc, ParsedXML | Get-ChildItem -recurse | ? {!($_.psiscontainer) -AND $_.lastwritetime -gt $Date} | % { write-host $_.fullname; Copy-Item -path $_.fullname -destination $destDrive} 
+0

嗨大卫,你的假设是正确的,($排除)不起作用。您的解决方案完美运作谢谢你的帮助! – Gbgk

+2

@Gbgk太棒了!你能否将我的解决方案标记为已回答?谢谢。 – David