所需功能:此脚本遍历Windows File Explorer和
的所有当前实例。这是我当前的脚本:
# Windows_FileExplorer_ListAllCurrentPaths.ps1
# Based on :: https://stackoverflow.com/a/31349468/1327508
# cls
"# $($env:computername) @ $([System.DateTime]::Now.ToString("yyyy-MM-dd hh:mm:ss"))`r`n" | out-file .\Windows_FileExplorer_OpenLastSavedPaths.ps1
"# PowerShell Script to OpenLastSavedPaths for Windows FileExplorer`r`n" | out-file -append .\Windows_FileExplorer_OpenLastSavedPaths.ps1
$app = New-Object -COM 'Shell.Application'
# $app.Windows() | Select-Object -Property * #
# $app.Windows() | Where-Object {$_.LocationURL -eq ''} | Select-Object * #
$app.Windows() |
Where-Object {$_.Name -eq 'File Explorer'} |
Select-Object LocationURL, LocationName, Name |
% {
$_.LocationURL = [regex]::Replace($_.LocationURL, "file:///", "ii ");
return $_;
} |
#foreach { $_.LocationURL } |
foreach { if ($_.LocationURL.length -gt 0) {$_.LocationURL} Else {"# [" + $_.Name + "] ? SearchWindow $([char]0x00BF) NoPath ? [locURL.length === " + $_.LocationURL.length + "] [" + $_.LocationName + "]"} } |
out-file -append .\Windows_FileExplorer_OpenLastSavedPaths.ps1
"`r`n" | out-file -append .\Windows_FileExplorer_OpenLastSavedPaths.ps1
"# Successfully Created PowerShell Script File:`r`n" | out-file -append .\Windows_FileExplorer_OpenLastSavedPaths.ps1
"# .\Windows_FileExplorer_OpenLastSavedPaths.ps1`r`n" | out-file -append .\Windows_FileExplorer_OpenLastSavedPaths.ps1
"`r`n" | out-file -append .\Windows_FileExplorer_OpenLastSavedPaths.ps1
get-Content .\Windows_FileExplorer_OpenLastSavedPaths.ps1
...脚本的问题是,对于当前正在查询中列出“搜索结果”的Windows资源管理器实例(即在搜索框中,您输入size:gigantic AND name:42
并按<Enter>
),然后我的脚本将生成以下内容:
# [File Explorer] ? SearchWindow ¿ NoPath ? [locURL.length === 0] [size:gigantic AND name:42]
...该脚本中当前还注释的是:
$app.Windows() | Where-Object {$_.LocationURL -eq ''} | Select-Object *
...因为我试图查找“地址栏”当前值在哪里,但似乎没有任何意义。