1

I have a script that searches for a file name in a folder and gives a folder path. Does Powershell have a way to make these folder paths a clickable link? I want to bring up a list of file directory paths that I can click on.

Here is what the code looks like.

#Declare Variables. 
$Software = @()

#Delcares Directories to search. 
$Directories = @(
    '\\Software\Unlicensed Software'
    '\\Software\Licensed Software')

#Gets folder contents of directories at a depth of three. 
Foreach($Directory in $Directories)
{ 
    $Path = Get-ChildItem $Directory -Recurse -Depth 3| ?{ $_.PSIsContainer } | Select-Object FullName;
    $Software += $Path
}

#Gets user string. 
$target = Read-Host -Prompt 'Input a software name or part of a name. ("Exit" to quit)';

#Finds matches and adds them to Links. 
while ($target -ne "exit")
{
   $count = 0;
   $Links = New-Object Collections.Generic.List[string];
    Foreach ($line in $Software)
    {   
        if($line -like "*$target*")
            {
                $Links.Add($line.FullName);
                $count += 1;
            }

#Stops code when results are greater than 100 entries. 
        if($count -gt 99)
            {
                Write-Output "Your search result yielded more than 100 entries. Try narrowing down your search."
                Break
            }
    }

#Prints links. 
    ForEach($Link in $Links)
    {
        Write-Output $Link;
    }
   Write-Host `n$count" entries found`n";

#Asks users if they would like to continue. 
   $target = Read-Host -Prompt 'Input a software name or part of a name ("Exit" to quit)';
}

#Exits Program
Write-Host "Press any key to continue ...";
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown");
2
  • 2
    There may be an easy way using Out-GridView -PassThru, tho you would need to share with us an example of your code. Commented Aug 6, 2021 at 19:22
  • Example code. Lets say that I have a folder path called: $FilePath ='\\Software\Licensed Software" I would like to click on a link called FilePath and be taken to the folder path. Commented Aug 6, 2021 at 20:32

2 Answers 2

2

This is a quite simple way you could use to select a folder an open it, it will display an Out-GridView until you cancel or close the grid and open the folder once you make a selection. If you're looking for something better looking and more complex you would have to code your own WinForm app.

$directories = Get-ChildItem $env:USERPROFILE -Directory |
               Select-Object Name, FullName

do
{
    $selection = $directories |
    Out-GridView -PassThru -Title 'Choose a Folder'

    if($selection){ Invoke-Item $selection.FullName }

} while($selection)
Sign up to request clarification or add additional context in comments.

Comments

0

You could make a HTML File:

Add-Type -AssemblyName System.Web
[System.Web.HttpUtility]::HtmlDecode((gci | select Name,@{n='Fullpath'; e={(("<a href='file://" +$_.fullname+"'>"+$_.Fullname+'</a>' ))}} | ConvertTo-Html)) | out-file c:\file.html
iex  c:\file.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.