I want create a few shortcuts on my desktop, it works locally. But when I try it on a remote PC I got only one shortcut for the first target (path1
), and script ignores path2
variable.
$Servers = Get-Content D:\1.txt
function add-sc {
param ([string[]]$Targets)
BEGIN {}
PROCESS {
foreach ($a in $Targets) {
$WshShell = New-Object -comObject WScript.Shell
$b = $a.Substring($a.length - 5)
$Shortcut = $WshShell.CreateShortcut("$Home\Desktop\$b.lnk")
$Shortcut.TargetPath = $a
$Shortcut.Save()
}
}
END {}
}
foreach ($server in $Servers) {
Invoke-Command -ComputerName $server -ScriptBlock ${function:add-sc} -Args "path1", "path2"
}