我正在编写一个简单的脚本来在一定天数后删除 USMT 迁移文件夹:
## Server List ##
$servers = "Delorean","Adelaide","Brisbane","Melbourne","Newcastle","Perth"
## Number of days (-3 is over three days ago) ##
$days = -3
$timelimit = (Get-Date).AddDays($days)
foreach ($server in $servers)
{
$deletedusers = @()
$folders = Get-ChildItem \\$server\USMT$ | where {$_.psiscontainer}
write-host "Checking server : " $server
foreach ($folder in $folders)
{
If ($folder.LastWriteTime -lt $timelimit -And $folder -ne $null)
{
$deletedusers += $folder
Remove-Item -recurse -force $folder.fullname
}
}
write-host "Users deleted : " $deletedusers
write-host
}
但是我一直在击中可怕的Remove-Item : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
我一直在寻找解决方法和替代方案,但它们都围绕着我关心文件夹中的内容。
我希望有一个更简单的解决方案,因为如果文件夹内容被标记为删除,我并不真正关心它。
除了Remove-Item -recurse之外,是否有任何本机 Powershell cmdlet可以完成我所追求的目标?