【发布时间】:2021-10-04 14:35:02
【问题描述】:
每个人。我正在尝试找出一种方法来读取 Windows 中目录的内容并查找具有特定文件扩展名的文件(在本例中为“.hod”),然后将每个文件的快捷方式创建到“C:\Users”中\公共\桌面。'
下面是我迄今为止在 PowerShell 中测试的一个示例(我知道它看起来非常糟糕)。我会很感激任何意见。谢谢。
$shortcutfiles = dir "C:\C:\IBM-Shortcuts\*.hod"
$DestinationDir = "C:\Users\Public\Desktop"
foreach ($shortcutfile in $shortcutfiles ) {
$TargetPath = Get-ChildItem "C:\IBMiACS-Shortcuts" -Filter *.hod -Recurse | % { $_.FullName }
$BaseName = Get-ChildItem "C:\IBMiACS-Shortcuts" -Filter *.hod -Recurse | % { $_.BaseName }
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$DestinationDir" & "$BaseName"+lnk)
$Shortcut.TargetPath = "$TargetPath"
$Shortcut.Save()
}
【问题讨论】:
标签: powershell shortcut