Solved

Powershell copy shortcut and point to other server

Posted on 2013-11-27
7
956 Views
Last Modified: 2013-12-03
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.

Thanks in advance.

$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
Comment
Question by:cwstad2
  • 4
  • 2
7 Comments
 
LVL 34

Expert Comment

by:Dan Craciun
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

by:cwstad2
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 34

Expert Comment

by:Dan Craciun
ID: 39682971
OK, please post a sample of your exchange.txt so I can get an idea of the hierarchical data.
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 15

Author Comment

by:cwstad2
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

by:cwstad2
ID: 39683558
is this even possible?
0
 
LVL 68

Accepted Solution

by:
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"

Open in new window

Then you could run
$sh = New-Object -Com WScript.Shell

import-csv C:\Users\Downloads\exchange.txt  | % {
  $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'
    $link.Save()
  }
}

Open in new window

0
 
LVL 15

Author Closing Comment

by:cwstad2
ID: 39692455
excellent thanks
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now