Windows 10 1903 にアップグレードしたら AppData\Roaming\Microsoft\Windows\Start\ Menu\Programs\Scoop\ Aps が空になった

Scoop で管理してるアプリケーションの Windows ショートカットが全滅した・・・

scoop update -f するのもだいぶ時間がかかりそうなのでショートカットだけを復旧する。

たまたま別の PC をほとんど同じ状態に構成してたので、Windows ショートカットを作るのに必要な情報を抽出。

dir -Path '.\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Scoop Apps\' -Recurse -Filter *.lnk `
| % { (New-Object -ComObject WScript.Shell).CreateShortcut($_.FullName) } `
| ConvertTo-Json > apps.json

apps.json を今の PC に移動して Windows ショートカットを作成。

ConvertFrom-Jsonjson の配列を入力しても後ろのパイプラインにはそれぞれの要素が渡らない、というところにちょっとはまった。

$WshShell = New-Object -ComObject WScript.Shell
$apps = Get-Content -Path apps.json | ConvertFrom-Json
$apps `
| ? { (Test-Path -Path $_.TargetPath) -and (Test-Path -Path $_.WorkingDirectory) } `
| % { `
    $Shortcut = $WshShell.CreateShortcut($_.FullName)
    $Shortcut.TargetPath = $_.TargetPath             
    $Shortcut.Arguments = $_.Arguments               
    $Shortcut.IconLocation = $_.IconLocation         
    $Shortcut.Description = $_.Description           
    $Shortcut.WorkingDirectory = $_.WorkingDirectory
    $Shortcut.Save()
}

参考