15 August 2016

How do I - Create a SharePoint 2013 sub site template when the UI option is not there?

SharePoint's publishing infrastructure and Features have been the bane of many a debug session I've been involved in.  SharePoint sites just behave differently when publishing is turned on.  Along with this, comes some menu and settings differences that Microsoft enforces for publishing sites.  Good, bad or indifferent, these nuances require some unique workarounds from time to time.

I have a client who is using publishing as part of their base site template.  Now the client wants to create a site template from a given sub site.  The template would then be used to create other sub sites in the same site collection.  Without publishing, this is no problem as you simply navigate to the Settings Gear > Site Settings > Site Actions > Save as template.  When publishing is turned on however, this option disappears from the settings page.
No problem you think.  I'm a smart and attentive SharePoint guru and I know what the "Save as template" page's URL is.  I'll just manually type it into the browser's address bar.  So you proceed to manually add _layouts/15/savetmpl.aspx to the current site URL so it would read something like this:
http://www.crayveon.com/sites/PublishingSite1/SubSiteA/_layouts/15/savetmpl.aspx
With confidence you press the key on your keyboard and...

















This is one of those little settings Microsoft made while trying to "protect" you from yourself.  OK, so how do we work around this one?
It's actually pretty easy once you know how the underlying process functions.  The "savetmpl.aspx" page does a lookup at the site property bag to see if there's a specific variable defined.  The variable is called "SaveSiteAsTemplateEnabled".  If it's defined, its value is checked and if set to "false", then the above error message is thrown and the template save process is aborted.
That said, we can work around this by using SharePoint Designer to change the variable value.  Here are the complete steps to overcome this little problem:
  1. Open SharePoint Designer 2013. 
  2. Open your target site e.g. http://www.crayveon.com/sites/PublishingSite1/SubSiteA  
  3. In the ribbon at the top, on the far right, click "Site Options". 
  4. On the Site Options dialog, under the "Parameters" tab, you will notice the target variable in question... "SaveSiteAsTemplateEnabled".  Its value should read "false".  Select the variable and click the "Modify" button on the right. 
  5. Change the value to "true" and click "OK". 
  6. Click "OK" to close the Site Options dialog window.
  7. From your browser, navigate to the target site e.g. http://www.crayveon.com/sites/PublishingSite1/SubSiteA
  8. From the target site, add "/_layouts/15/savetmpl.aspx" to the URL of the site e.g. http://www.crayveon.com/sites/PublishingSite1/SubSiteA/_layouts/15/savetmpl.aspx and press Enter.
  9. You should be presented with the Save as Template page. 
  10. Fill out your desired options and click "OK" to save the template.
Provided you don't have any custom apps on the site that are not compatible with templatization, the result should be successful.  If you do have custom apps, you'll have to remove said apps and then try saving as a template again.

Enjoy!
C




18 July 2016

How do I - Exclude certain file types from a XCopy folder sync?

When you're managing multiple SharePoint farms that rely on custom, in-house developed Powershell modules, keeping these modules up to date across the entire enterprise can be a tricky prospect.  This is usually where I employ some Powershell with calls to XCopy.

XCopy is a very powerful tool for synching files between systems.  As you can see from its documentation page, there are many command switches for it.  The tricky thing is usually when you're trying to sync folders that contain Powershell scripts, but these scripts generate log files.  You want to sync the .ps1 files, but not the .log files.  How do we do that then?

This is where the /exclude: switch comes into play.  You can create a text file containing the extensions you wish to exclude.  Then you simply pass the text file to the /exclude: switch thus:

xcopy S:\Corne\Scripts\*.* T:\Scripts /E /I /F /H /R /Y /d /exclude:Exclusions.txt

Its important to remember that the exclusion will do a simple path match on the values specified in exclusions.txt.  As such, having the file content defined thus:

.log

will exclude anything that matches ".log" somewhere in the path of the file e.g. files ending in ".logger", ".logs", ".log2, ".log" etc. will all be excluded from XCopy.  This can be resolved by simply adding a backslash to the back of the extension thus:

.log\

Now XCopy will only ignore files with a ".log" extension.

Enjoy
C

18 June 2016

Powershell Tip - Padding Text

Since we use Powershell for just about everything these days, you're sure to end up generating some kind of quick report of something in SharePoint through a simple Powershell script.  Inevitably, the need to pad text comes up.  Powershell makes it easy to left and right pad text variables through the use of the .PadLeft() and .PadRight() .NET methods used as follows:

$str = "My Report Title";
$strPad = $str.PadLeft(20) + ".";
Write-Host $strPad;

The output looks like this:

     My Report Title.

In this case, we were left padding the string to 20 characters.  By default, padding is done with spaces so given the string was already 15 characters long, 5 spaces were added to the front of the string resulting in our output.  The use of the additional period will become apparent as we look at right padding the text as follows:

$strPad = $str.PadRight(20) + ".";
Write-Host $strPad;

The output looks like this:

My Report Title     .

Here you can clearly see the 5 spaces before the period. ;-)
If you want to pad with something other than spaces, you can simply supply the second, optional parameter to PadLeft() or PadRight() specifying the character to be used for padding e.g.

$strPad = $str.PadRight(20, "$") + ".";
Write-Host $strPad;

The output looks like this:

My Report Title$$$$$.

Enjoy!
C


22 May 2016

How do I - Round numbers to a given decimal space in Powershell?

One of my subscribers asked how to round in Powershell.  It's actually quite easy.  All you have to do is use the [math] preprocessor's Round() method e.g. if I wanted to round to two decimal places I'll use the following:

[math]::Round($value, 2);

If I issue the Round() call without a second parameter thus:

[math]::Round($value);

I would get an integer rounded value, i.e. I'd get the whole, ignoring any decimals.

Hope that helps!

Later
C

16 April 2016

How do I use Powershell with IIS 7 or later?

If you're into any form of automation, you know that Powershell rocks!
That said, the real strength of Powershell comes from it's snap-ins.  These extensions allow you to do all manner of things.  One of those is the ability to script actions in IIS.  To get started you'll need to ensure you have the Feature installed on your flavor of Windows.  If you don't have it installed, you can either download it here:

https://www.microsoft.com/en-us/download/details.aspx?id=7436

or add it via Windows' Programs and Features.  Generally on anything late Windows 7 or Server 2008, it's already loaded.

Once installed, you'll need to load the snap-in thus:

Import-Module WebAdministration
From here, you're only limited by the available calls and your imaginations.

Happy scripting.
C

SharePoint Remote Event Receivers are DEAD!!!

 Well, the time has finally come.  It was evident when Microsoft started pushing everyone to WebHooks, but this FAQ and related announcement...