Configure SharePoint Blocked File Types using PowerShell

A very nice set of Powershell scripts to manage blocked file type for a web application by Ryan Dennis.

Worth to have on your toolbox:

 

See you,
Amadeu.
Advertisements

Deploy Content Files to SharePoint Using SharePoint.DesignFactory.ContentFiles

I’ve been working with SharePoint 2010 for different projects and teams for a while and one thing that has been always a challenge is the source control and publishing process on content items (such as JavaScript, images and CSS files).

Visual Studio SharePoint projects allow us to create modules to deploy these kind of files but it has a big drawback. When you do it, the files are deployed as “file definitions” – ghostable on the libraries. If a user customize the files, any new deployment will not update the instance on your site, only the file definition. If you want to see the updated version of the file you should go to SharePoint Designer and reset the specific file to its definition.

This is pretty bad and makes lots of people confused on why the file wasn’t updated.

I was trying to find a solution for this issue when a found a blog post by Serge van den Oever explaining the installation of a very interesting extension to Visual Studio 2010 to solve this issue. It is called SharePoint.DesignFactory.ContentFiles.

The extension allows you to:

  • deploy content files from your Visual Studio to your local machine using the SharePoint API or to remote machines using the SharePoint client API.
  • map folders on your solution to document libraries and special folders on a SharePoint site so you can deploy files to different locations.
  • deploy files checking them out, in, publishing and approving it.
  • deploy only files that have changed since the last deployment.
  • customize the commands to deploy your solution – check documentation for details.

To install it follow the steps on the article SharePoint.DesignFactory.ContentFiles – Installation. The extension was built using the NuGet tool for Visual Studio. You need to have NuGet installed on your Visual Studio before running the extension. It also needs the MME extension to allow the tool to create custom menus on the project and items right-click menu.

After the installation, your Visual Studio project should contain some extra items:

  • _MachineConfiguration folder: this folder contains Powershell scripts to tell the extension where to deploy the files. By default it will look for a script called default.ps1, then for one with the machine name or for a custom one if specified when the deploy command is called.
  • _Tools folder: this folder contains batch files, Powershell scripts, reference DLLs ,documentation and other support files used by the extension.
  • Mappings.xml: file used to map folders from the Visual Studio project to the document libraries on the SharePoint site.
  • packages.config: Nuget configuration file to tell it to load the extension.

The installation worked just fine for me. I had only to check and tweak a few items to make it work.

After the installation is done, just check if you have a DLL named VSMenuManager.SharePoint.DesignFactory.ContentFiles.dll on your solution folder.

Edit the mappings.xml file to make sure you have all mapped folders created on your Visual Studio project otherwise the deployment will fail.

Create a copy of the Sample.ps1 file on the _MachineConfiguration folder with the name Default.ps1. Configure it with your machine’s web application URL and the settings for the deployment type (object model or client object model), user name, password and claims authentication usage.

After that just add the files you want to deploy to the folders and deploy all files to your web application. The output window can show you the progress of the deployment:

The documentation provides a very good insight on how to use and configure the extension and can be very useful. It can be found under the _Tools\Documentation folder.

If you need to create custom Configurations to deploy to different environments you can do that by following the steps on the Configuration part of the documentation.

In order to get my custom configurations to work I had to edit the Deploy.cmd and the Redeploy.cmd to accept thew configuration name as a parameter.

I added the %1 parameter by the end of line 2 on both files and it worked just fine.

You should test and see how much easier is to deploy content files to SharePoint 2010!

Thanks Serge! The SharePoint.DesignFactory.ContentFiles is really awesome!!!

See you,

Amadeu.

Powershell Week – Day 5: Viewing and Setting SharePoint Diagnostic Logging levels using Powershell

Whenever you install a new SharePoint farm you might go thru that annoying task of setting the ULS and the Event Log levels. This is one of the moments our friend Powershell can give us a good hand.

Follow a few scripts to help you check your current settings and set new values for entire areas or specific sections.

List the main areas of the Log configuration:

get-sploglevel | select-object area | sort-object -property 'area' -unique

List the details of all the areas of the Log configuration:

get-sploglevel | format-table area , name

List the configured log level for one specific area:

get-sploglevel -identity "SharePoint Server:*" | format-table name, eventseverity, traceseverity

Set the log level as Error for the Event Log and Monitorable for the ULS log for one specific area:

set-sploglevel -identity "SharePoint Server:*" -eventseverity Error -traceseverity Monitorable

My suggestion is for you to analyze which services you use on your farm and define the log levels according the importance of the services for your implementation. There is nothing wrong with settings only high severity events on the log if you don’t monitor it regularly and only want to see major issues. If you have a situation where it is important to have the logs in more detailed level, you can set the logs to different levels only when debugging and set it back to the regular level after the issue is solved.

See you,

Amadeu.


Powershell Week – Day 4: Copying Files Between Document Libraries

Day 4 of the Powershell Week is all about copying files from one document library to another.


# Source document library full path
$source = "http://yourwebapplication.com/web/sourcedoclib"
# Destination document library full path
$destination = "http://yourwebapplication.com/web/destinationdoclib"

$sourceList = Get-SPList $source
$sourceFieldCol = $sourceList.Fields;
$sourceItems = $sourceList.GetItems();

$destinationList = Get-SPList $destination

foreach($spListItem in $sourceItems) {
 $newSPListItem = $destinationList.RootFolder.Files.Add($spListItem.Name, $spListItem.File.OpenBinary()).Item;;

foreach($spField in $sourceFieldCol) {
 if ($spField.ReadOnlyField -ne $True) {
 $newSPListItem[$($spField.InternalName)] = $spListItem[$($spField.InternalName)];
 }
 }
 $newSPListItem.Update();
}

Get the script here.
See you,

Amadeu.

Powershell Week – Day 3: List Items With Unique Permission

This script can be used to list all items in a web application with unique permissions or broken permissions inheritance.

It can be useful when trying to diagnose permissions issues on big web application with lots of sites and lists/document libraries.


$webAppURL = "http://yourwebapplication.com"

function CheckItemsWithUniquePermissions() {
 $webapp = Get-SPWebApplication $webAppURL

foreach ($site in $webapp.Sites)
 {
 $allwebs = $site.allwebs
 foreach($web in $allwebs)
 {
 $webURL = $web.url
 write-output "[WEB] Processing Web $webURL"

 foreach ($list in $web.Lists)
 {
 $listName = $list.title
 write-output "[LIST] Processing List $listName"

 foreach ($item in $list.Items)
 {
 $itemTitle = $item.title
 $uniquePermissions = $item.HasUniqueRoleAssignments

 if($uniquePermissions -eq "True")
 {
 write-output "[ITEM] Item '$itemTitle' - Unique Permissions: $uniquePermissions"
 }
 }

 $uniquePermissions = $list.HasUniqueRoleAssignments

 if($uniquePermissions -eq "True")
 {
 write-output "[LIST] List '$listName' - Unique Permissions: $uniquePermissions"
 }
 }

 $uniquePermissions = $web.HasUniqueRoleAssignments

 if($uniquePermissions -eq "True")
 {
 write-output "[WEB] Web '$webURL' - Unique Permissions: $uniquePermissions"
 }
 }
 }
}

CheckItemsWithUniquePermissions

You can get the script file here.

See you,

Amadeu.

Powershell Week – Day 2: Copying Lists

The second post of the Powershell Week is about copying lists. I found this to be very interesting when you have multiple copies of a environment (for several developers, for instance) and needs to synchronize the data structure and content between them.

I based these 2 scripts on the article Copying Lists with PowerShell in SharePoint 2010 from Jerry Orman.

I created 2 scripts:

One to export the data

$sourceWebUrl = "http://yourwebapplicationurl.com"

# path to save the exported data
$path = "c:\data\export\"

#comma delimited list of List names to copy
$lists = @("List1", "List2")

#comma delimited list of Document Libraries to copy
$libs = @("DocLib1", "DocLib2")

foreach($list in $lists)
{
    "Exporting List " + $list
    export-spweb $sourceWebUrl -ItemUrl ("/lists/" + $list) -IncludeVersions All -path ($path + $list + ".cmp") -force
    "Exporting complete."
}

foreach($lib in $libs)
{
    "Exporting Document Library " + $lib
    export-spweb $sourceWebUrl -ItemUrl ("/" + $lib) -IncludeVersions All -path ($path + $lib + ".cmp") -force
    "Exporting complete."
}

And one to import the data.

$destWebUrl = "http://yourwebapplicationurl.com"

# path to load data from
$path = "c:\data\import\"

#comma delimited list of List names to copy
$lists = @("List1", "List2")

#comma delimited list of Document Libraries to copy
$libs = @("DocLib1", "DocLib2")

foreach($list in $lists)
{
   "Importing List " + $list
   import-spweb $destWebUrl -path ($path + $list + ".cmp") -force
   "Importing complete."
}

foreach($lib in $libs)
{
   "Importing Document Library " + $lib
   import-spweb $destWebUrl -path ($path + $lib + ".cmp") -force
   "Importing complete."
}

I hope you find it useful as well.

See you,
Amadeu.

Powershell Week – Day 1: Copy List Structure Using Template

This week I’m starting a series of posts with several Powershell scripts I’ve been writing to help with some activities that might take a long time if you do it manually. I hope you enjoy the Powershell scripts as I do!

This first one is about creating a list or document library based on an existing one. The approach used is to save the existing library as a template and then creating the new one based on the template.

$site = get-spsite("http://www.yourwebapplication.com")
$web = $site.Allwebs["your web site"]
$list = $web.Lists["your library"]
$list.SaveAsTemplate("TemplateName.stp", "TemplateName", "Template Name", $false)
# the last parameter defines wheter you want the data to be saved in the template

$listTemplates = $site.GetCustomListTemplates($web)
$web.Lists.Add("New List URL", "New list Name", $listTemplates["TemplateName"])

If you want, you can also delete the template after the copy is created.

See you,

Amadeu.