Archive

Archive for August, 2012

Hide Content Type Columns in SharePoint 2010 List Settings using PowerShell

August 28, 2012 4 comments

Recently I was asked “why can’t I hide my content type columns in my SharePoint 2010 list if the column types are set to (Yes/No)”.  This was something new to me.  I was unsure of the answer, but after looking at all the content type columns with their types set to Yes/No I noticed every single one of them did not have the option to change the list settings.  It was grayed out.  I needed to hide a few content type columns that had type sets of Yes/No but could not do it through the list settings.  So I turned to PowerShell.

If you ever run into this problem just follow my PowerShell script below to Hide/Unhide Content Type columns with their column type set, set to Yes/No. 

This script assumes you have a multiple Lists that have the same Content Type Columns that you want to hide.

If you only have 1 list than you would simply just remove the foreach loop and if statement and add this line after the $web call.

$list = $web.List[“Name of List”]

———————————————————————————————————————————————————————————–

$web = Get-SPWeb http://portal/site

foreach($list in $web.Lists) #Loop through each list in Site
{
 if($list.BaseType -eq “GenericList”)  #Only select SharePoint 2010 Lists
 {
  $contentTypes = $list.ContentTypes[“Name of Content Type”]
  $field = $contentTypes.FieldLinks[“Name of Content Type Column”]
  $field.Hidden = $true #Set the Content Type Column to Hidden
  $contentTypes.Update() #Update Content Type
  $list.Update() #Update List
 }
}
$web.Dispose()

———————————————————————————————————————————————————————————-

If you are not sure the name of the Content Type you can follow one of my other blogs to get the Content Type Name

http://jshidell.com/2012/08/16/finding-all-content-types-in-sharepoint-20072010-site-using-powershell/

If you want to reset the Content Type Column back to Optional, just replace this line:

$field.Hidden = $true

with

$field.Hidden = $false

Getting The Last Modified Date for All List/Document Libraries in a SharePoint 2007 Site Collection using PowerShell

August 22, 2012 1 comment

If you ever needed to grab a list of all the list and document libraries that were recently last modified on a specific site collection in SharePoint 2007 you can follow the script below.

This might come into handy during a  migration where you would like to see if there were any list or libraries that might have been modified during or after the migration.

——————————————————————————————————————————————————–

#Load SharePoint 2007 Assemblies

[System.Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”) | out-null

$siteUrl=”http://portal/site”
$site=new-object Microsoft.SharePoint.SPSite($siteURL)

#Enter the date you want to compare, leave the date blank if you want the current date.
$date = Get-Date 8/22/2012

foreach($web in $site.AllWebs)
{
    “Site ” + $web.Url >> c:\temp\LastModified.txt
    
    foreach($list in $web.Lists)
    {
        if($list.LastItemModifiedDate -gt $date) #if list item modified date is greater than $date write to text file
        {
            “—-List” + $list.Title >> c:\temp\LastModified.txt
            “——–Last Modified” + $list.LastItemModifiedDate >> c:\temp\LastModified.txt
        }
    }
web.Dispose()
}
site.Dispose()

—————————————————————————————————————————————————–

Getting a list of all Workflow Associations from a SharePoint 2007 Site Collection using PowerShell

August 20, 2012 2 comments

Migrating from SharePoint 2007 to SharePoint 2010 takes a lot of preparation and coordination to have a successful migration.  This means taking into consideration all customizations, permissions, and workflows.  To prepare for a migration between SharePoint 2007 and SharePoint 2010 I wanted to get a list of all workflows (SPD & Nintex) on a specific Site Collection before migration.
Below is the script I used in SharePoint 2007 to do this, and spits out a .csv file.  Later I will update this blog posting to show you how to do it in SharePoint 2010

——————————————————————————————————————————————————–

***UPDATED SCRIPT TO US A FUNCTION TO GENERATE A HASH TABLE TO EXPORT TO A .CSV FILE, FOR BETTER FORMATTING**********************

#Load SharePoint 2007 Assemblies
[System.Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bc111e9429c”) | out-null

$siteurl=”http://portal/site”
$site=new-object Microsoft.SharePoint.Site($siteurl)

#Initialize Workflow Count variable
$workflowcount = 0

#Foreach loop to loop through all webs, and lists with workflow associations, and exclude workflows that have previous versions and write findings to .csv file.

function Get-Workflows()
{
    foreach($web in $site.AllWebs)
    {
            foreach($list in $web.Lists)
            {
                foreach($wf in $list.WorkflowAssociations)
                {
                        if ($wf.Name -nolike “*Previous Version*”)
                        {
                            $hash = @{“[URL]”=$web.Url;”[List Name]”=$list.Title;”[Workflow]”=$wf.Name}
                             New-Object PSObject -Property $hash | Sort-Object

                        }
                }
            }
    }
}

foreach($web in $site.AllWebs)
{
    foreach($list in $web.Lists)
    {
        foreach($wf in $list.WorkflowAssociations)
        {
            if ($wf.Name -nolike “*Previous Version*”)
            {
               $workflowcount += 1
            }
        }
    }
}

Get-Workflows | Export-csv c:\temp\workflows.csv
“Workflow Count ” + $workflowcount >> c:\temp\workflows.csv

$site.Dispose()

——————————————————————————————————————————————————

Finding All Content Types in SharePoint 2007/2010 Site Using PowerShell

August 16, 2012 1 comment

If you ever needed to just see which content types are being utilized on your SharePoint 2007/2010 Site you can grab these content types using Power Shell.

Since SharePoint (MOSS) 2007 does not already come pre-installed with Windows PowerShell 2.0 you will have to download a copy and install it onto your WFE  you can grab it here- http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=20430

For SharePoint 2010 PowerShell comes installed so you would just open up the SharePoint 2010 Management Shell.

After installing Windows PowerShell below is the script that can be used to grab all Content Types on a specific Site in SharePoint 2007.

—————————————————————————————————————————————————-

1.  Open up Windows PowerShell 2.0 with Admin rights.
2.  Next Type:

#Load the SharePoint 2007 Assemblies.  This is needed for Windows PowerShell to communicate with SharePoint

[System.Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral,PublicKeyToken=71e9bce111e942c”) | out-null

$siteUrl=”http://portal/site”
$site=new-object Microsoft.SharePoint.SPSite($siteurl)

$web=$site.RootWeb

foreach($ctype in $web.ContentTypes)
{$ctype.Name}

—————————————————————————————————————————————————–

If you are searching for a specific content type you can use this.

—————————————————————————————————————————————————–

#Load the SharePoint 2007 Assemblies.  This is needed for Windows PowerShell to communicate with

SharePoint[System.Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral,PublicKeyToken=71e9bce111e942c”) | out-null

$siteUrl=”http://portal/site”
$site=new-object Microsoft.SharePoint.SPSite($siteurl)

$webs = $site.AllWebs

foreach($web in $webs)
{

    foreach($lst in $web.lists)
    {
        
        foreach($item in $lst.Items)
        {
            
            if ($item.ContentType.Name -like “*<name of contenttype>*)
            {Write-Host $web.Url “-” $item.ContentType.Name “-” $item.Url}

        }

    }
    $web.Dispose()
}

—————————————————————————————————————————————————–

For SharePoint 2010 just replace the first three lines of both of these scripts with this line.

$webs = get-spsite http://portal/sites | get-spweb

Fixing SharePoint 2010 Site Collection Feature Activation Error: The field with Id {GUID} defined in feature {GUID} was found in the current site collection or in a sub site

August 15, 2012 1 comment

I recently ran into a problem on a newly migrated Site Collection in my SharePoint 2010 environment that prevented me from activating the Nintex Workflow 2010 site collection feature on the site.  When I tried to activate the feature I was presented with the error below:

The field with Id {GUID} defined in feature {GUID} was found in the current site collection or in a sub site

Since the migration team is using Metalogix to migrate content between SharePoint 2007 to SharePoint 2010, Nintex does not play nice when Migrating data using a 3rd party Migration Tool (Metalogix, DocAve, etc).

If the Site on SharePoint 2007 has the Nintex Workflow feature activated on the site prior to migration, and the new site on SharePoint 2010 does not have this feature already activated [prior to data migration] then you will receive the above error when trying to activate later.

Apparently some data migration tools detect that a site column or content type from the SharePoint 2007 Site is not present in the SharePoint 2010 site so it then recreates these assets on the SharePoint 2010 site.  In this case, it will recreate a Nintex Workflow-installed content type and site column even though Nintex has not been activated.

The data migration tool then forcibly creates a column somewhere in the site collection that the Nintex Workflow feature activation cannot overwrite, preventing it from activating.

There are two workaround this problem.

1.  Activate the Nintex Worklow feature on the SharePoint 2010 Site Collection prior to any type of data migration from SharePoint 2007 to SharePoint 2010
2.  Nintex developed a handy tool called FeatureSiteColumnCleanup that recursively searches the SharePoint 2010 site for any Nintex Content Types and Columns and then removes them.

You can get that tool here – http://download.nintex.com/sl/supportfiles/support_utilities/NW2010/FeatureSiteColumnCleanup.zip

You would copy this file to one of your SharePoint WFE’s or CA boxes and run it from the command line.

If you just want a report of all Nintex content types and columns on your site you would run this command:

FeatureSiteColumnCleanup.exe “siteCollectionUrl”  -includeRootWeb

If you want to delete all Nintex content types and columns from your site you would run this command:

FeatureSiteColumnCleanup.exe “siteCollectionUrl” -includeRootWeb -deleteFound

Delete Columns From SharePoint 2010 List/Library using PowerShell

August 1, 2012 3 comments

There might be some cases where there are some columns in your SharePoint 2010 list or document libraries that are no longer needed,  and they need to be deleted.  However some of these columns do not have the option to delete through the List/Document Settings within SharePoint.

Time to turn to PowerShell.  Below is the script to successfully remove columns from SharePoint 2010 list/document libraries.

—————————————————————————————————————————————————–

$web = Get-SPWeb -identity http://portal/site
$list = $web.Lists[“Name of List”]
$column = $list.Fields[“Name of Column”]
$column.Hidden = $false
$column.ReadOnlyField = $false
$column.Allowdeletion = $true
$column.Sealed = $false
$column.Delete()
$list.Update()

—————————————————————————————————————————————————–