Solved

# Powershell copy shortcut and point to other server

Posted on 2013-11-27
998 Views
Hi guys i have the following code below which works great for copying FF to the servers in the txt file. However id like to go one step further and copy the shortcut for the FF.exe to another server. What would be the best way to achieve this.

$servers =Get-Content "C:\Users\Downloads\exchange.txt" foreach ($servers1 in $servers ) {$copy = Copy-Item -Path C:\FirefoxPortable -Filter *.* -Destination "\\$servers1\c$\it" -Recurse

}
0
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 4
• 2

LVL 35

Expert Comment

ID: 39682925
$WshShell = New-Object -comObject WScript.Shell$Shortcut = $WshShell.CreateShortcut("\path\to\shortcut)$Shortcut.TargetPath = "\path\to\target"
$Shortcut.Save() HTH, Dan 0 LVL 15 Author Comment ID: 39682955 Hi Dan its a little bit complicated so i will give more details. im copying from server1 for example to london1 which is where the full app will be and the shortcut will be copied to london2 and london3 for example. But there are many other sites for example so would i need 1 txt file with all of the 2 and 3 servers but how will they point to server1 of that site. Each 2 and 3 server has to point to the shortcut on server1 for that site. Hope this makes sense 0 LVL 35 Expert Comment ID: 39682971 OK, please post a sample of your exchange.txt so I can get an idea of the hierarchical data. 0 LVL 15 Author Comment ID: 39682997 for example this is whats in the exchange.txt file. but on each site there is a 2 and 3 server. so the shortcuts would need to be to london2 and london3 for example but ref back to the .exe on london1 london1 newyork1 paris1 0 LVL 15 Author Comment ID: 39683558 is this even possible? 0 LVL 70 Accepted Solution Qlemo earned 500 total points ID: 39683616 You would need to have two columns. One for the copy target and link target, and a second for the list of servers the link should be created on: server, linksrv "london1", "london2,london3" "paris1", "paris2, paris3"  Then you could run $sh = New-Object -Com WScript.Shell

$target = '\\' +$_.server + '\c$\it\' Copy-Item -Path C:\FirefoxPortable -Destination$target -Recurse
foreach ($srv in$_.linksrv -split ',') {
$link =$sh.CreateShortcut('\\' + $srv + '\C$\users\Public\Desktop\Firefox.lnk')
$link.TargetPath =$target + 'firefox.exe'
}
}

0

LVL 15

Author Closing Comment

ID: 39692455
excellent thanks
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
###### Suggested Courses
Course of the Month8 days, 17 hours left to enroll