【发布时间】:2021-08-06 19:11:30
【问题描述】:
我有一个在文件夹中搜索文件名并给出文件夹路径的脚本。 Powershell 是否有办法使这些文件夹路径成为可点击的链接?我想调出一个可以点击的文件目录路径列表。
这是代码的样子。
#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");
【问题讨论】:
-
使用
Out-GridView -PassThru可能是一种简单的方法,但您需要与我们分享您的代码示例。 -
示例代码。假设我有一个名为的文件夹路径:$FilePath ='\\Software\Licensed Software" 我想单击一个名为 FilePath 的链接并转到文件夹路径。
标签: powershell directory hyperlink clickable