$d1=get-date -format "yyyyMMdd"
New-Item -ItemType Directory -Force -Path D:\kingdee\$d1
New-PSDrive -Name "z" -PSProvider FileSystem -Root "\\172.16.200.11\d$\KingDee-bak"
Copy-Item -Path Z:\* -Recurse -Destination D:\kingdee\$d1\
remove-item Z:\* -recurse
Remove-PSDrive z
#delete kingdee backup files, only keep 7 days.
$limit = (Get-Date).AddDays(-7)
$path = "D:\kingdee"
Get-ChildItem -Path $path -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit } | Remove-Item -Force
Get-ChildItem -Path $path -Recurse -Force | Where-Object { $_.PSIsContainer -and (Get-ChildItem -Path $_.FullName -Recurse -Force | Where-Object { !$_.PSIsContainer }) -eq $null } | Remove-Item -Force -Recurse