Using PowerShell to Bulk Upload Files to SharePoint

While building a school’s Learning Gateway I needed to bulk upload all their student images into a picture library so that the My Children web part could display them. Since there were several hundred of them I wrote a little PowerShell script to perform this.

$siteUrl = "http://sharepoint/schools/test"
$listName = "Students Picture Library"

$site = New-Object Microsoft.SharePoint.SPSite($siteUrl)
$web = $site.OpenWeb()
$list = $web.Lists[$listName]
$fileCollection = $list.RootFolder.Files

$files = get-childItem -Exclude *.ps1

foreach ($file in $files)
    $stream = $file.OpenRead()
    $uploaded = $fileCollection.Add($file.Name, $stream, $TRUE)
    "Uploaded " + $file.Name

    if ($stream) {$stream.Dispose()}

if ($web) {$web.Dispose()}
if ($site) {$site.Dispose()}

In order to use this:

  1. Save as as .ps1 file in the same folder as the files to upload.
  2. Change the site url and name of the list at the beginning of the script to your values
  3. Make sure that only the files to upload and the ps1 file is in the folder
  4. Open PowerShell using Run As Administrator
  5. Navigate to the folder
  6. Run the .ps1 file

The script will then iterate through all files in the current folder and upload them to the given list, overwriting them if they already exist.

Read More

Update a Dll in the GAC From the Command Line

I’ve blogged before on how to Easily add a dll to the GAC, but that involves two instances of Windows Explorer and the mouse.

It would be quicker and easier to use the command line to update a dll in the GAC. You can do this with the Global Assembly Cache Tool gacutil, but this is only present if you have the .net SDK or Windows SDK installed. This is going to be the case with your development machine, but you don’t really want to be installing it on all your test servers.

To get round this I knocked up a quick utility which will remove an existing version of a dll from the GAC and then install the latest version. The code is:

using System;
using System.Globalization;
using System.EnterpriseServices.Internal;

namespace Test
public class GacInstall
public static void Main(string[] arguments)
string assemblyPath = arguments[0];
Publish publish = new Publish();
catch (Exception e)

You can then use it by passing it the dll you want as a command line parameter e.g.

GacInstall MyUpdatedCode.dll

Assuming that MyUpdatedCode.dll is in the same directory.

Combined with my last tip Recycle An Individual Application Pool From The Command Line you can now write a bat or cmd file to replace the dll in the GAC and recycle the application pool with 2 key presses: The up arrow key and then return.

Read More

Recycle An Individual Application Pool From The Command Line

When developing SharePoint artifacts which live in the GAC you have the following options to get your new release in as part of the development process:

  1. Build your installation package and upgrade it
  2. Put the new dll in the GAC and run iisreset
  3. Put the new dll in the GAC and recycle the SharePoint application pool
    This is because SharePoint will only pick up updated dlls in the GAC after a recycle.

As it is an iterative process when you are developing this happens a lot, so ideally you need a process which is as quick as possible. 1 & 2 take the longest time so you should aim to use 3.

Luckily there is a command line command which will recycle individual application pools, which will be quicker than using the IIS administration tool. The command is

C:\windows\System32\inetsrv\appcmd.exe recycle apppool "SharePoint – 80"

Where you replace "SharePoint – 80" with the name of your application pool.

Of course when releasing to a live server you should always go down the proper installation package upgrade, this tip is purely for development purposes on your development server.

There’s a lot more you can do with appcmd – it’s a utility for making configuration changes to IIS so pretty much anything you can do through the IIS MMC snap in can be done via it. There are more details about appcmd on Technet or you can run

C:\windows\System32\inetsrv\appcmd.exe /?

to get help details.

Note: appcmd is for IIS7 not IIS6.

Read More

Learning Gateway Conference 2010, 14 July London


If you are in education and using SharePoint then the Learning Gateway Conference is the must attend event of the year. Run by Alex Pearce (MVP) and myself it follows on from the highly successful first Learning Gateway Conference last year. This year will be even bigger and better! We have added a whole new track which is dedicated to leading SharePoint schools telling us their stories of how they have implemented their Learning Gateways, what has worked for them and what pitfalls to avoid.

With the recent release of SharePoint 2010, it is an exciting time in the SharePoint world and the educational pricing makes it a great product for use in schools, colleges and local authorities. However, in addition to covering some of the fantastic new features in SharePoint 2010, we will still have lots of content for SharePoint 2007. So whether you have already moved to SharePoint 2010, are planning to upgrade over the summer or don’t currently have any plans to change, there will be lots of great information you can take away and use in your Gateway.

With both technical and user oriented sessions there is something for everybody – network managers, technicians, users, Learning Gateway managers or members of senior leadership teams. In addition the conference will be relevant and useful whether you are an experienced SharePoint user, just starting out or just considering SharePoint. With 3 concurrent tracks running throughout the day it would be worth considering having more than one attendee!

In addition to the content it will of course be a great networking event with the opportunity to meet others in the same situation as you and discuss what you are doing. At only £150 for the day it’s an unrivalled professional development opportunity providing information you will be able to put in practice straight away.

The venue is Church House, Westminster in Central London so is easy to get to from almost anywhere.

For more information visit the conference web site and register today. To whet your appetite here is a list of the sessions:

Building the Gateway

User Adoption

School Stories

Understanding SharePoint 2010

2010 Social Networking Features

Parental Engagement


Encouraging user adoption & quick wins

How we drove usage

Patching SharePoint and Preparing your SharePoint 2007 for 2010

SharePoint 2010 for Education

Hosted SharePoint

A look at live@edu

Integrating InfoPath Forms

How we use our in-school SharePoint


SharePoint Learning Kit

Replacement of the File Server

We hope to see you there on the 14th!



Read More