PowerShell で 特定フォルダ配下 の 特定ファイルのみのショートカット を作成する

フォルダの階層が深く、かつ細分化されているので、ドキュメントとなるファイルの把握が難しい。
特定の拡張子のショートカットを作成する事で、ファイルの把握とアクセスの利便性をあげる。

前提条件

  • Windows 7 Professional
  • $PSVersionTable PSVersion=5.0.10586.117

create_file_shortcut.ps1

$sourcePath = "{入力パス}"
$targetPath = "{出力パス}"
$include = [string[]]("*.docx", "*.xlsx")

$result = Get-ChildItem -Path $sourcePath -Include $include -Recurse
$wscriptShell = New-Object -ComObject WScript.Shell

foreach ($fileInfo in $result) {

    $shortcut = $wscriptShell.CreateShortcut($targetPath + "\" + $fileInfo.Name + ".lnk")
    $shortcut.TargetPath = $fileInfo.FullName
    $shortcut.Save()
}

Write-Host "finish!"