How do I get rid of duplicate desktops?

TEST YOUR SMARTS
Which of the following retains the information it's storing when the system power is turned off?
  • ROM
  • CPU
  • RAM
  • GPU
Submit »
88% of IT pros got this right.
Challenge
×
Get answers from your peers along with millions of IT pros who visit Spiceworks.
Join Now

A lot of my users float and sadly Windows 10 loves to create new desktop icons in their folder when they log on. So with folder redirection some of them have 15 edge icons. I'm trying to write a powershell script to clean this up but it doesn't seem to work?
Any ideas?


Powershell
#Set Desktop Path $DesktopPath = [Environment]::GetFolderPath["Desktop"] #Array of shortcut names that often duplicate $DuplicateNames = @[ @{Name="Edge"} @{Name="Chrome"} @{Name="Teams"} ] $GetChildItem = Get-ChildItem -Path $DesktopPath -Include "*.*" -Recurse foreach [$ChildItem in $GetChildItem] { foreach[$DuplicateName in $DuplicateNames] { if[$ChildItem -contains $DuplicateName -and $ChildItem -contains "]" ] { Remove-Item -Path $ChildItem } } }
  • PowerShell[137]
Best Answer
Thai Pepper
OP
francishagyard2
This person is a verified professional.
Verify your account to enable IT peers to see that you are a professional.
Aug 23, 2019 at 08:14 UTC
PowerShell expert
190 Best Answers
329 Helpful Votes

This worked well for me:

Powershell
$DesktopPath = Join-Path -Path [[Environment]::GetFolderPath["Desktop"]] -ChildPath "*" $DuplicateNames = @[ "*Edge*", "*Teams*", "*Chrome*" ] Get-ChildItem -Path $DesktopPath -Filter *.lnk -Include $DuplicateNames | Where {$_.Name -like "*- Copy*.lnk"} | Remove-Item -Force
Edited Aug 23, 2019 at 09:40 UTC
View this "Best Answer" in the replies below »

2 Replies

· · ·
Thai Pepper
OP
Best Answer
francishagyard2
This person is a verified professional.
Verify your account to enable IT peers to see that you are a professional.
Aug 23, 2019 at 08:14 UTC
PowerShell expert
190 Best Answers
329 Helpful Votes

This worked well for me:

Powershell
$DesktopPath = Join-Path -Path [[Environment]::GetFolderPath["Desktop"]] -ChildPath "*" $DuplicateNames = @[ "*Edge*", "*Teams*", "*Chrome*" ] Get-ChildItem -Path $DesktopPath -Filter *.lnk -Include $DuplicateNames | Where {$_.Name -like "*- Copy*.lnk"} | Remove-Item -Force
Edited Aug 23, 2019 at 09:40 UTC
1
· · ·
Pimiento
OP
jeremykowalski Dec 2, 2019 at 23:18 UTC
1st Post

We're running into the issue but with a variety of programs, especially as we begin to move towards pushing Known Folder Move through Group Policy causing every user-based program to create duplicates on each computer. What I've come up with so far is this:

Powershell
gci -path [[Environment]::GetFolderPath["Desktop"]] -filter "* - Copy*.lnk" | % {if [test-path[[$_.fullname -split "[ - Copy]"][0]+".lnk"]] {ri $_.fullname -force}}

For each desktop " - Copy" shortcut, verify if we have a non-copy version as well. If we do, remove the copy. If there is no 'base' version, leave the copy or copies until a base version is inevitably recreated. Repeat until done.

0

This topic has been locked by an administrator and is no longer open for commenting.

To continue this discussion, please ask a new question.

Video liên quan

Chủ Đề