尝试将更新的快捷方式复制到通配符路径。当我在本地计算机上的测试场景中运行代码时,该代码有效:
$Source1 = "C:\Temp\Updated Shortcut\MyShortcut.lnk"
$destination1 = "C:\Temp\Users\*\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\MyShortcut.lnk"
Get-ChildItem -Path $destination1 | ForEach-Object { Copy-Item -Path $Source1 -Destination $_.DirectoryName }
Run Code Online (Sandbox Code Playgroud)
但是针对生产目标路径运行它不起作用:
$Source1 = "C:\Temp\Updated Shortcut\MyShortcut.lnk"
$destination1 = "U:\Users\*\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\MyShortcut.lnk"
Get-ChildItem -Path $destination1 | ForEach-Object { Copy-Item -Path $Source1 -Destination $_.DirectoryName }
Run Code Online (Sandbox Code Playgroud)
如果删除通配符并使用实际路径,它也将起作用:
$Source1 = "C:\Temp\Updated Shortcut\MyShortcut.lnk"
$destination1 = "U:\Users\JohnSmith\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\MyShortcut.lnk"
Get-ChildItem -Path $destination1 | ForEach-Object { Copy-Item -Path $Source1 -Destination $_.DirectoryName }
Run Code Online (Sandbox Code Playgroud)
U:\ Users文件夹中确实包含1181个文件夹(1181个用户中的每个文件夹),因此不确定是否也可能是一个问题?