5

我是 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")
4

1 回答 1

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}
于 2012-11-13T01:44:04.147 回答