Skip to main content

Posts

Showing posts with the label PowerShell

Useful PowerShell Scripts

Have started a project to collect some powerful and useful PowerShell scripts that are really handy when working with Microsoft technologies like SharePoint, SQL Server etc. Here you go: http://ups.codeplex.com Scripts included in the initial release: create document library create site Content Type report on active Site Collection features  Will add more scripts there as I go.

Delete Published Content Type from a Document Library

If you use a content type that has been published from a Content Type Hub in your document library then if you decide to delete that content type from the document library you might experience the problem - for some reason published content types are made read only when you add them to libraries. Example 1. We have got a document library with published content type "BaseDocument": 2. If we try deleting it from the library we are getting an error: "The content type "X" at "Document Library Y" is read only." Solution Using SharePoint API we can update the ReadOnly property and then delete the content type. Here's the PowerShell script sample: $siteurl = "http://siteurl" $ctname = "BaseDocument" $libname = "Shared Documents" $site = Get-SPSite $siteurl $web = $site.OpenWeb() $list = $web.Lists[$libname] $ct = $list.ContentTypes[$ctname] $ct.ReadOnly = $false $ct...

Import Excel files to SharePoint 2010

Sometimes we have a need to transfer Excel spreadsheet to the SharePoint 2010 environment. Because Excel is very popular business application, I see quite a few spreadsheets out there that are used for managing complex business operations. At some stage the decision comes up to move Excel-based system to SharePoint for certain good reasons and business users try to upload their spreadsheets to SharePoint lists and libraries. It might seem obvious that we could use out-of-the-box functionality provided by Microsoft in SharePoint 2010 which is "Import Spreadsheet" which "creates a list which duplicates the columns and data of an existing spreadsheet". What it does in reality is: allowing you to select a range of cells, creating a list with all columns as single or multiple lines text. That's it. So for real life scenarios we need a different approach to import Excel data to SharePoint appropriately. In the scenario here we have got a simplified application manage...

SharePoint 2010 Foundation Audit Settings

I have recently implemented audit for SharePoint 2010 Foundation using PowerShell. There was a couple of discussions where some people said it's impossible to enable audit in SharePoint 2010 Foundation: http://social.msdn.microsoft.com/Forums/en/sharepoint2010general/thread/53e79142-88c9-48f1-b5a5-a6259c9f6f97 http://social.msdn.microsoft.com/Forums/en/sharepoint2010general/thread/ec1e2e7e-2fcf-4d16-8c25-a44198b651d9 Solution: 1. Go to Start -> All Programs -> Microsoft SharePoint 2010 Products -> SharePoint 2010 Management Shell 2. When it is loaded you then run the following command to get your site collection object: $site = Get-SPSite http://site_URL 3. If you don't get errors then execute the following commands one by one to set audit options and update it: $site.Audit.AuditFlags = [Microsoft.SharePoint.SPAuditMaskType]::Update $site.Audit.Update() 4. [Microsoft.SharePoint.SPAuditMaskType]::Update is a enum value of type SPAuditMaskType. You can hav...