PowerShell 从远程 PC 中删除桌面项目 [英] PowerShell to delete Desktop Items from a remote PC

查看:46
本文介绍了PowerShell 从远程 PC 中删除桌面项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 200 台电脑需要删除一些特定的图标.

I have 200 PC that need to have some specific icons removed.

我用 ComputerName(每行 1 个名称)创建了一个 CSV 文件

I created a CSV file with the ComputerName (1 name per row)

我有另一个文件,其中包含需要从桌面上删除的图标的文件名(Shortcut1.lnk 等).另一个文件也是一个 CSV(每行 1 个文件名).

I have another file with the file name of the icon that needs to be removed from the desktops (Shortcut1.lnk, etc). This other file is also a CSV (1 file name per row).

如何运行 PowerShell 脚本来删除这些图标.(请注意,并非我的 CSV 文件中的所有计算机都已开启.有些计算机可能已关闭或存在网络问题).

How can I run a PowerShell script to remove those icons. (Please note that not all computers in my CSV file maybe turned on. Some maybe off or have network issues).

$SOURCE = "C:\powershell\shortcuts"
$DESTINATION = "c$\Documents and Settings\All Users\Desktop"
$LOG = "C:\powershell\logs\logsremote_copy.log"
$REMOVE = Get-Content C:\powershell\shortcuts-removal.csv

Remove-Item $LOG -ErrorAction SilentlyContinue
$computerlist = Get-Content C:\powershell\computer-list.csv

foreach ($computer in $computerlist) {
  foreach ($file in $REMOVE) {
    Remove-Item "\\$computer\$DESTINATION\$file" -Recurse
  }
}

到目前为止,这是我的代码,但似乎没有从中删除文件

This is my code so far but it doesn't appear to delete the files from

\\computername\c$\Documents and Settings\All Users\Desktop

我收到错误和警告.日志文件似乎也没有创建.

I am getting errors and warnings. The log file also doesn't seem to be creating.

无论如何要获得有关已删除内容的报告.什么没有被删除?

Anyway to get a report of what was deleted. what was not deleted?

推荐答案

改变这个,你已经在你的 $destination 变量中指定了一个斜线,你被加倍了@\\c$

Change this, you already specify a slash in your $destination variable, you are double up @ \\c$

Remove-Item "\\$computer$DESTINATION\$file" -Recurse

否则,您尝试删除此路径并失败.

otherwise, you are trying to delete this path and failing.

\\computername\\c$\Documents and Settings\All Users\Desktop\$file

这篇关于PowerShell 从远程 PC 中删除桌面项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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