/build/static/layout/Breadcrumb_cap_w.png

Deleting all Links to a file in a folder

I needed to delete the contents of a folder for every user this is located in C:\users. Used the following ps script. Now i need to delete any links that there might be to this folder or an exe file in this folder; cant seem to figure out how. Any help will be appreciated
-------------------------------------------------------------------------------------------------------

$users = Get-ChildItem c:\users | ?{ $_.PSIsContainer }
foreach ($user in $users){
    $userpath = "C:\Users\$user\Gems"
    Try{
        Remove-Item $userpath\* -Recurse -ErrorVariable errs -ErrorAction SilentlyContinue  
    } 
    catch {
        "$errs" | Out-File c:\temp\allegroerror.txt -append
    }
}
-------------------------------------------------------------------------------------------------------

0 Comments   [ + ] Show comments

Answers (1)

Posted by: python 8 years ago
Senior White Belt
1
Found a resolution online. Change Target as needed
----------------------------------------
function Get-StartMenuShortcuts{
    $DesktopShortcuts = Get-ChildItem -ErrorAction SilentlyContinue -Recurse "C:\Users" -Include *.lnk
    $StartMenuShortcuts = Get-ChildItem -ErrorAction SilentlyContinue -Recurse "C:\ProgramData\Microsoft\Windows\Start Menu" -Include *.lnk

    $Shortcuts = $DesktopShortcuts + $StartMenuShortcuts

    $Shell = New-Object -ComObject WScript.Shell
    foreach ($Shortcut in $Shortcuts)
    {
        $Properties = @{
        ShortcutName = $Shortcut.Name;
        Path = $Shortcut.FullName;
        ShortcutDirectory = $shortcut.DirectoryName
        Target = $Shell.CreateShortcut($Shortcut).targetpath
        }
        New-Object PSObject -Property $Properties
    }

    [Runtime.InteropServices.Marshal]::ReleaseComObject($Shell) | Out-Null
}

$ShortcutList = Get-StartMenuShortcuts
$ShortcutList | Where-Object{$_.Target -like "*Hello.exe"} | Remove-Item -ErrorAction SilentlyContinue

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ