【发布时间】:2019-01-04 21:35:35
【问题描述】:
我有一个 powershell 脚本,可以将快捷方式收藏夹从 Windows 7 Windows 资源管理器复制到文本文件。
这是一个有效的脚本:
$ShortcutsFile = 'H:\_ProfilBackup\Genveje.txt'
# Copy Shortcuts to file
if (!(Test-Path $ShortcutsFile)) { New-Item -Path $ShortcutsFile -ItemType File -Force | Out-Null }
$Shortcuts = Get-ChildItem -Recurse "$HOME\Links" -Include *.lnk
$Shell = New-Object -ComObject WScript.Shell
foreach ($Shortcut in $Shortcuts){
$Properties = @{
Shortcuttarget = $shortcut.Target
Target = $Shell.CreateShortcut($Shortcut).targetpath | Out-File $ShortcutsFile -Append
}#$Properties
New-Object PSObject -Property $Properties
}#foreach
[Runtime.InteropServices.Marshal]::ReleaseComObject($Shell) | Out-Null
我的问题是:
我只能在执行以下操作时获取文件的所有链接路径属性:
Out-File from the PSObject -Property $Properties = @{
Target = $Shell.CreateShortcut($Shortcut).targetpath | Out-File $ShortcutsFile -Append
有没有人知道如何将所有链接路径属性获取到一个变量?
$shortcut.Target 只有最后一个文件链接
有谁知道另一种方法吗?
【问题讨论】:
标签: powershell