Powershell 中用户输入的通配符功能
Wildcard functionality on a user input in Powershell
我目前正在编写一个 powershell 脚本,它接受用户输入并搜索目录中具有相似名称的所有项目。
$filename = '*test*.*'
$searchinfolder = 'C:\example'
Get-ChildItem -Path $searchinfolder -Filter $filename -Recurse | %{$_.FullName}
我需要的是让它在保持第一行功能的同时接受用户输入。到目前为止我用过:
$filename = Read-Host -Prompt 'Input word'
我需要做什么才能维持功能?例如
它找到文件夹 test 和 test1
@Lee_Dailey在评论中给出了解决方案。
$filename = Read-Host -Prompt 'Input word'
$filename = '*{0}*.*' -f $fileName
Get-ChildItem -Path $searchinfolder -Filter $filename -Recurse | %{$_.FullName}
我目前正在编写一个 powershell 脚本,它接受用户输入并搜索目录中具有相似名称的所有项目。
$filename = '*test*.*'
$searchinfolder = 'C:\example'
Get-ChildItem -Path $searchinfolder -Filter $filename -Recurse | %{$_.FullName}
我需要的是让它在保持第一行功能的同时接受用户输入。到目前为止我用过:
$filename = Read-Host -Prompt 'Input word'
我需要做什么才能维持功能?例如 它找到文件夹 test 和 test1
@Lee_Dailey在评论中给出了解决方案。
$filename = Read-Host -Prompt 'Input word'
$filename = '*{0}*.*' -f $fileName
Get-ChildItem -Path $searchinfolder -Filter $filename -Recurse | %{$_.FullName}