问题
I have 200 PC that need to have some specific icons removed.
I created a CSV file with the ComputerName (1 name per row)
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).
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?
回答1:
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
来源:https://stackoverflow.com/questions/20667310/powershell-to-delete-desktop-items-from-a-remote-pc