Download Prerequisites

While I was doing some installation for the TAP of one of my customers with strong restrictions (no internet connectivity for my test server) I had to develop a script for downloading prerequisites. You will say, but why? There are scripts online that do that for you…well the ones I found were all hard-coded for SPS2014 Prerequisites.

Of course I cannot disclose which prerequisites these are, but I can share the script and how to get the prerequisites in a text file.

So this is the code you need to download the prerequisites.


param (
[string] $InputFilePath = "mytextfile.txt",
[string] $OutputPath = "[some drive letter]:\somedirectory\"
)

$webclient = New-Object System.Net.WebClient
$creds = Get-Credential -Credential ([Security.Principal.WindowsIdentity]::GetCurrent()).Name;
$webclient.Proxy.Credentials = $creds

$urls = get-content $InputFilePath;

foreach( $url in $urls ) {
$webRequest = [net.WebRequest]::Create($url)
$webresponse = $webrequest.GetResponse();
$fileName = $webresponse.responseuri.segments[$webresponse.responseuri.segments.Length -1]
$filePath = $OutputPath + $fileName;
$webresponse.Close();

$webclient.DownloadFile($url,$filePath);
}

The text file looks something like this…


http://go.microsoft.com/fwlink/?LinkID=
http://go.microsoft.com/fwlink/?LinkID=
http://go.microsoft.com/fwlink/?LinkID=
...
http://go.microsoft.com/fwlink/?LinkID=

The text file can be generated by using one of the following links (using strings.exe or process explorer on a machine that cannot host sharepoint):

http://thesharepointfarm.com/2014/03/sharepoint-prerequisite-installer-download-links/
https://technet.microsoft.com/en-us/sysinternals/bb897439

I used sysinternals\strings.exe. That worked very well.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: