生成PowerShell文件以存档/重新打开所有当前的Windows File Explorer实例

时间:2018-11-29 14:42:35

标签: windows powershell windows-explorer

所需功能:此脚本遍历Windows File Explorer和

的所有当前实例。
  1. 创建/保存新的PowerShell脚本以重新打开它们
  2. 在当前PowerShell窗口中显示已保存脚本的内容,以允许用户将其复制/粘贴到同一PowerShell窗口中,然后从那里重新打开它们。

这是我当前的脚本:

#  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 *

...因为我试图查找“地址栏”当前值在哪里,但似乎没有任何意义。

0 个答案:

没有答案
相关问题