Advertisement
illwill

Delete Dead Shortcuts Powershell

Aug 13th, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $Shortcuts = Get-ChildItem -Recurse "C:\" -Include *.lnk
  2.  
  3. $Shell = New-Object -ComObject WScript.Shell
  4. foreach ($Shortcut in $Shortcuts)
  5. {
  6.     $Properties = @{
  7.     ShortcutName = $Shortcut.Name
  8.     Path = $Shortcut.FullName
  9.     ShortcutDirectory = $Shortcut.DirectoryName
  10.     Target = $Shell.CreateShortcut($Shortcut).targetpath
  11.     }
  12.     New-Object PSObject -Property $Properties
  13.  
  14.     if (-not (Test-Path $Properties.Target)) {Remove-Item $Properties.Path -Force -ErrorAction 0}
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement