首页 > 系统相关 >PowerShell 备份与定期删除文件

PowerShell 备份与定期删除文件

时间:2023-01-05 10:13:18浏览次数:47  
标签:Force 删除 Item 备份 Recurse kingdee _. Path PowerShell

$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

标签:Force,删除,Item,备份,Recurse,kingdee,_.,Path,PowerShell
From: https://www.cnblogs.com/bayue9/p/17026764.html

相关文章