删除W2K3回收站中的内容 [英] Deleting contents of W2K3 recycle bin

查看:174
本文介绍了删除W2K3回收站中的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编写Powershell脚本,从虚拟服务器的回收站中删除所有内容.由于某种原因,我在查找Windows 2003回收站的路径时遇到了错误,并且无法找到回收站以删除其中的所有内容.想知道这里有人可以给我一些有关此代码段我做错了什么的建议:

Writing a Powershell script that deletes all the contents from the recycle bins for virtual servers. For some reason I'm running into an error with finding the path for the Windows 2003 recycle bin and can't locate bin in order to delete everything in it. Was wondering if anyone here could give me some advice on what I am doing wrong with this code-snippet:

if($serverVersion.name -like '*2003*'){
$dir = "\\$server" + '\C$\recycled'
}
elseif($serverVersion.name -like '*2008*'){
$dir = "\\$server" + '\C$\$recycle.bin'
}

$recycleArray = @()
foreach ($item in get-childitem -path $dir){
    $recycleArray += $item
}

for ($i = 0; $i -le $recycleArray.length; $i++){
    $removal = $dir + "\" + $recycleArray[$i]
    remove-item $removal -force -recurse 
    }

我能够从W2K8回收站中正确删除所有内容,因此一旦我找到了回收站的路径,代码就可以正常工作.这是我为那些好奇的人收到的错误消息的图片:

I'm able to delete everything from the W2K8 recycle bin correctly so the code should work correctly once I'm able to find the path to the recycle bin. Here's a picture of the error message I receive for those curious in seeing:

出于好奇,是否有办法减少所有这些代码并为2003年和2008年制作2个单行代码?我意识到,我目前编写的方法并没有利用Powershell的cmdlet,而是希望在我弄清楚W2K3回收站出了什么问题后对其进行改进.

Also, out of curiosity, is there a way to cut down all this code and make 2 one-liners for both 2003 and 2008? I realize that the current way I've written this out doesn't take advantage of Powershell's cmdlets and want to improve on it once I've figured out what's wrong with W2K3 recycle bin.

推荐答案

问题是在widows server 2003 c:\ recycler的此位置未找到回收站,因此jsut更改了代码,应该工作.

The problem is that the recycle bin is found on this location in widows server 2003 c:\recycler not c:\recycled so jsut change your code and it should work.

尝试此代码,看看它是否可以解决问题

Try this code and see if it fixes the problem

if($serverVersion.name -like '*2003*'){
$dir = "\\$server" + '\C$\recycled'
}
elseif($serverVersion.name -like '*2008*'){
$dir = "\\$server" + '\C$\$recycle.bin'
}


foreach ($item in get-childitem -path $dir){
     remove-item $item.FullName -Force -Recurse
}

这篇关于删除W2K3回收站中的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆