SPFest Chicago: Jack Fruh’s SharePoint PowerShell Time Machine

“Gosh that takes me back… or is it forward? That’s the trouble with time travel, you can never tell.”

~ The Fourth Doctor in Dr. Who

Attending Jack Fruh‘s session, SharePoint PowerShell Time Machine, at SharePoint Fest Chicago has persuaded me. If you are a SharePoint Administrator, having a collection of PowerShell scripts running on a scheduled basis is better than having a TARDIS when it comes to getting information from the past to save time in the future. (You may argue that the TARDIS is cooler – and I am certainly not going to disagree – but, if we are honest, we know that the unpredictability of TARDIS’s short-range guidance, relative to the size of the universe, would make it an unreliable SharePoint tool.)

Clearly, the opportunity to become a Time Lord of SharePoint was appealing to many, and Jack whets our “wannabe” appetites by demoing some administrator-friendly back-in-time scripts, including:

  • Enabling versioning on document libraries
    • Jack showed us how easy it is to not only turn on versioning across all sites but also to specify the number of major versions that you want to keep so users can easily go back in time to see earlier iterations of documents.
  • Recording current permission levels on sites
    • You know that one day someone is going to find his way to the Site Permissions and click Inherit Permissions to see what happens. With a scheduled job that records site permissions, recovery is no longer a daunting, time-consuming process.
  • Estimating your upcoming hardware requirement
    • It’s about that time when organizations plan for the next year. Capturing the size of a Site Collection or Content Db on a regular basis allows your projections to be based on past growth trends
      rather than a wild guess.

Each of these PowerShell scripts begs to be regularly scheduled.  If you need a quick refresher on Windows Task Scheduler.

Almost as important as capturing the information is having a logging structure. Each script Jack presented used variables to give each file a unique timestamp and name. If you are scheduling jobs and outputting log files to the same directory, including a similar structure in your scripts will save you time down the road.

Note the script below from Enable Versions on every SharePoint Site with PowerShell (updated with logging):

   1: Add -PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
   3: $timestamp= get- date - format "yyMMdd_hhmmtt"
   4: $filenameprefix ="location_where_file_will_be_savedFilename
   5: $logfile= ("{0}_{1}.csv" -f $filenameprefix, $timestamp)
   8: $header = " this is vary from script to script"
   9: $header| out-file  -FilePath $logfile

# filenameprefix – Identifies where the files will be stored on your machine and the name of the file.

# logfile – Shows how Jack likes to format his files, but there are lots of ways to do this.

# out – File will not append, it will overwrite. However, with the timestamp, it is very unlikely that two files will have the same name.

Some additional handy tips from Jack included:

  • Using * copy filename will merge together multiple files. (This works from the command prompt, not PowerShell, but think about how easy this would make it to present an excel chart of disk capacity over time to support your cry for additional hardware!)
  • Use $false not false
  • Notepad ++ is “awesome

In the session, he also stated that you’d be given information that you could use on your first day back in the office. Not only is it true, but if you are a SharePoint Admin, it should not be put off!

“You know how it is; you put things off for a day and next thing you know, it’s a hundred years later.”

~ The Fifth
Doctor in Dr. Who