Skip Ribbon Commands
Skip to main content

Quick Launch

Todd Klindt's home page > Todd Klindt's SharePoint Admin Blog > Posts > Downloading SharePoint Patches with PowerShell
December 08
Downloading SharePoint Patches with PowerShell

I’ve been known to patch a SharePoint server here and there. Once in a while, when I’m on a customer server its Internet Explorer security settings will prevent me from being able to download a patch. I’ll go to my favorite patch list, toddklindt.com/sp2016builds or toddklindt.com/sp2013builds, and pick the patch I want. But when it comes down to getting the patch the IE security settings will prevent me from actually downloading said patch. Sadness ensues. I’ve had to do various dances to get the patches and recently I’ve started leveraging PowerShell more and more to do so. After a conversation with Jason Himmelstein I agreed to publish the PowerShell I use. Jason promised me you wouldn’t laugh. So you can’t laugh.

I also made a video of how to use it.

clip_image002

The Usage

I packaged this as a function, Get-TKMSKBDownload, and while it’s in a module, you can easily paste it into any existing module file you might already be using.

To use this function download TKDownloadFile.psm1.txt. Remove the “.txt” at the end to rename it to TKDownloadFile.psm1, Rename-Item .\TKDownloadfile.psm1.txt .\TKDownloadFile.psm1. Then Import it into your PowerShell session with Import-Module TKDownloadFile to let it know it’s there.

clip_image004

I have lovingly provided some Help and Examples to help you use it. In trying to address all of the situations where I’ve done this, I made sure the function worked with either details.aspx and confirmation.aspx URLs for the download link.

clip_image006

To use it, go to my patches page and click the Download link for the patch you want. Then copy that URL out of your browser and paste it after the function, like in the example:

Get-TKMSKBDownload -url https://www.microsoft.com/en-us/download/confirmation.aspx?id=56230

It will download the patch into your current directory. It should look like this when it runs:

clip_image008

After the file is downloaded you can run it and patch your SharePoint server.

I won’t paste all the code in this blog post, (download it here) but I do want to highlight a couple of pieces of it. First, this is the line I use to get the direct link to the patch download, where $url is the link from the patches page:

$downloadurl = ((Invoke-WebRequest -UseBasicParsing -Uri $url).links | Where-Object -Property data-bi-cN -Like -Value "click here to download manually" | select -First 1).href

Before I wrote this PowerShell I had a couple of instances where I needed the direct link to the patch. I had had to use the Developer Tools in Chrome to find the URL in the Microsoft Download web page. I was able to use that information to craft the line above. If you’re curious, you can start with the part inside of the parenthesis (Invoke-WebRequest -UseBasicParsing -Uri $url) and see how the page is loaded as an object by PowerShell. There is some interesting stuff in there.

The other part I needed was the name of the file to save. That’s part of the $downloadurl object, so I used this PowerShell to put off the file name, which is everything after the final / character, plus 1 so we don’t get the / itself:

$file = $downloadurl.Substring($downloadurl.LastIndexOf("/") + 1)

With those two pieces of information I’m able to pull the patch down and save it.

Invoke-WebRequest -UseBasicParsing -Uri $downloadurl -OutFile $file

As always, I had a couple of people look this code. Thanks to Shane Young and Jeff Hicks for all of that. Jeff had some great ideas for a v2 of this, like being able to specify a download directory, or backgrounding the download job. All good ideas, but I didn’t want to delay the publication of this blog post to implement them. If I keep using this module I may add them later. If I do, I’ll update this blog post.

Once again, if you’d like to see all of this magic in action, you can watch my HowTo video on YouTube.

tk

ShortURL: http://toddklindt.com/PSDownloadMSPatch

Comments

Re: Downloading SharePoint Patches with PowerShell

Great post! I am actually getting ready to across this information, is very helpful my friend. Also great blog here with all of the valuable information you have. Keep up the good work you are doing here.
http://sli-therio.com
 on 12/12/2017 10:54 PM

Connected PowerShell

Connected PowerShell script is very helpful to get detail statements of all reports in a SharePoint Site Collection or site and subsites. This script will place all report libraries which also system libraries. http://www.helpinessays.com/someone-write-my-essay.html
 on 12/13/2017 4:37 AM

obat hernia

Obat Hernia <a href="http://obathernia.best-agaric.com/"rel="external">Obat Hernia Yang Sangat Efektif Menghilangkan Benjolan</a>
Obat Hernia <a href="http://obathernia.agaricpro.info/"rel="external">Obat Hernia Alami Solusi Ampuh Tanpa Operasi</a>
Obat Hernia <a href="http://obathernia.bestagaric.web.id/"rel="external">Obat Hernia Anak Dan Dewasa Paling Mempan Tanpa Operasi</a>
Obat Hernia <a href="http://obathernia.bestagaric.com/"rel="external">Obat Hernia Yang Sudah Melalang Buana Di Seluruh Nusantara</a>
Obat Hernia <a href="http://obathernia.bestagaric.org/"rel="external">Obat Hernia Makbul Yang Akan Melenyapkan Permasalahannya</a>
Obat Hernia <a href="http://obathernia.agaricpro.web.id/"rel="external">Obat Hernia Cespleng Yang Tidak Bisa Dipandang Sebelah Mata</a>
Obat Hernia <a href="http://obathernia.agaricpro.biz/"rel="external">Obat Hernia Yahud Pemberi Kesembuhan Pada Anak Dan Dewasa</a>
Obat Hernia <a href="http://obathernia.bestagaric.net"rel="external">Obat Hernia Ampuh Dengan Kemujaraban Yang Sangat Luar Biasa</a>
 on 12/13/2017 9:14 PM

 Norton setup

Step by Step guide for Norton Setup, Download & complete installation online. We are providing independent support service if in case you face problem to activate or Setup your product

<a href="http://www.nortonhelp.me/">www.norton.com/setup</a>
[URL="http://www.nortonhelp.me"]www.norton.com/setup[/url]
http://www.nortonhelp.me
 on 12/21/2017 12:25 PM

Office setup

Step by Step guide for Office Setup, Download & complete installation online. We are providing independent support service if in case you face problem to activate or Setup your product

<a href="http://office.com.developsetup.online">www.office.com/setup</a>
[URL="http://office.com.developsetup.online"]www.office.com/setup[/url]
http://office.com.developsetup.online
 on 12/21/2017 12:25 PM

Kaspersky support number

Step by Step guide for Kaspersky Activation, Download & complete installation online. We are providing independent support service if in case you face problem to activate or Setup your product

<a href="http://www.activation-kaspersky.com/"> activation.kaspersky.com </a>
[URL="http://www.activation-kaspersky.com"]activation.kaspersky.com[/url]
http://www.activation-kaspersky.com
 on 12/21/2017 12:26 PM

thanks your post

Thanks for your post! It's been a long time since I read a good article and such a meaning! I hope you will continue to write articles like these for hobbyists! Good luck!
http://iogames-online.com
 on 12/27/2017 4:02 AM

thanks your post

Thanks for your post! I think there are many other people who are interested in them just like me! How long does it take to complete this article? I have read through other blogs, but they are cumbersome and confusing. I hope you continue to have such quality articles to share! Good luck!
http://happywheels8.com
 on 12/28/2017 9:39 PM

thanks your post

I think there are many other people who are interested in them just like me! How long does it take to complete this article? I have read through other blogs, but they are cumbersome and confusing. I hope you continue to have such quality articles to share! Good luck!
http://vex-3.com
 on 1/7/2018 10:56 PM

office.com/setup - Enter Office Product Key – Office Setup | 1-844-666-8616

Enter Key for Office.com/setup, after purchasing Office from visit office.com/setup, sign in to your www.office.com/setup account then enter product key for Office Setup | 1-844-666-8616

Any More Information
https://office.com-setup-activation.com/

Thank You
 on 1/13/2018 3:04 PM
1 - 10Next

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Title


Body *


Today's date *

Select a date from the calendar.
Please enter today's date so I know you are a real person

Twitter


Want a message when I reply to your comment? Put your Twitter handle here.

Attachments

 

 Please Support my Sponsors