locked
How to recursively find shortcuts whose target point to a particular server IP RRS feed

  • Question

  • I have a rather large directory containing multiple subfolders containing subfolders.  Is there a script that will search through the entire directory structure, and give me a list of shortcuts whose target point to a particular server's IP address?
    Tuesday, July 22, 2014 4:54 PM

Answers

  • This script uses PowerShell.

    # List all .lnk files and their image paths
    #Replace variables IPAddress and Path with values for your environment.
    $IPAddress = "IP address to filter on"
    Function Get-Shortcuts
    {
    $Path = "Directory_to_Search"
    $Items = Get-ChildItem $Path -Recurse -Include *.lnk, *.url 
    ForEach ($Item in $Items) {
       $Shell = New-Object -ComObject WScript.Shell 
       $Properties = @{
            ShortcutName = $Item.Name 
            Target = $Shell.CreateShortcut($Item).targetpath 
                }
    New-Object PSObject -Property $Properties 
    } 
    [Runtime.InteropServices.Marshal]::ReleaseComObject($Shell) | Out-Null
    }
    
    Get-Shortcuts | Where {$_.Target -like "*$IPAddress*"}
    
    ###Adapted from http://www.computerperformance.co.uk/powershell/powershell_create_shortcut.htm


    • Marked as answer by RJO22 Thursday, July 24, 2014 1:12 PM
    Tuesday, July 22, 2014 7:51 PM

All replies

  • Probably not but you are free to write one.  I recommend using PowerShell but you will have to master the shell object.  Look in the 'Gallery' for examples of using shortcuts.


    ¯\_(ツ)_/¯

    Tuesday, July 22, 2014 4:57 PM
  • This script uses PowerShell.

    # List all .lnk files and their image paths
    #Replace variables IPAddress and Path with values for your environment.
    $IPAddress = "IP address to filter on"
    Function Get-Shortcuts
    {
    $Path = "Directory_to_Search"
    $Items = Get-ChildItem $Path -Recurse -Include *.lnk, *.url 
    ForEach ($Item in $Items) {
       $Shell = New-Object -ComObject WScript.Shell 
       $Properties = @{
            ShortcutName = $Item.Name 
            Target = $Shell.CreateShortcut($Item).targetpath 
                }
    New-Object PSObject -Property $Properties 
    } 
    [Runtime.InteropServices.Marshal]::ReleaseComObject($Shell) | Out-Null
    }
    
    Get-Shortcuts | Where {$_.Target -like "*$IPAddress*"}
    
    ###Adapted from http://www.computerperformance.co.uk/powershell/powershell_create_shortcut.htm


    • Marked as answer by RJO22 Thursday, July 24, 2014 1:12 PM
    Tuesday, July 22, 2014 7:51 PM
  • Thanks Mark!
    Thursday, July 24, 2014 1:12 PM