SharePoint Tech Blog

29/07/2010

Enumerate SharePoint features using Powershell

Filed under: PowerShell, SharePoint — Tags: , — kctnpblog @ 8:42 pm

This code requires the SharePoint Powershell Profile to be loaded.

To execute the code, provide the site url as a command line parameter.
e.g. powershell .\listfeatures.ps1 http://site

The output lists the features on the web application, site collection and web.


function writefeature($featureobj) {
$featuredef=$featureobj.DefinitionId;
$feature=$farm.FeatureDefinitions[$featuredef];
"{0,-40} {1,-50} {2,-40}" -f $feature.Id , $feature.DisplayName , $feature.Scope;
}

function setwindowsize() {
$pshost = get-host
$pswindow = $pshost.ui.rawui

$newsize = $pswindow.buffersize
$newsize.height = 3000
$newsize.width = 150
$pswindow.buffersize = $newsize

}

#Sets the size of the window to display well formatted output
setwindowsize

#Get command line parameter for url
$url=$args[0];

$farm = Get-SPFarm;

"Web application features"
$webapp = Get-SPWebApp $url;
$webapp.Features | ForEach-Object {
writefeature $_;
}

""
"Site collection features"
$spsite=Get-SPSite -url $url;
$spsite.Features | ForEach-Object {
writefeature $_;
}
$spsite.Dispose();

""
"Web features"
$spweb=Get-SPWeb -url $url;
$spweb.Features | ForEach-Object {
writefeature $_;
}
$spweb.Dispose();

03/05/2010

Create SharePoint Audiences using Powershell

Filed under: SharePoint — Tags: , — kctnpblog @ 12:49 am

This is a modified version of the codeplex script for creating SharePoint audiences. I find this a bit easier to use since it uses an xml file as its input.
This code requires the SharePoint Powershell Profile to be loaded.

[Void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.Audience");
#
$url="http://localhost";
#
$spsite=Get-SPSite -url $url;
$spcontext=[Microsoft.Office.Server.ServerContext]::GetContext($spsite);
$searchcontext=[Microsoft.Office.Server.Search.Administration.SearchContext]::GetContext($spsite)
$spsite.Dispose();
#
$audmanager=New-Object Microsoft.Office.Server.Audience.AudienceManager($spcontext);
$audcollection=$audmanager.Audiences;
#
[xml]$adata=Get-Content .\audiences.xml
#
$adata.Audiences | ForEach-Object {
$audname=$_.Audience.Name;
$auddesc=$_.Audience.Description;
$newaud=$audcollection.Create($audname,$auddesc);
$newaud.AudienceRules=New-Object System.Collections.ArrayList;
$_.Audience.Rule | ForEach-Object {
$property=$_.Property;
$operator=$_.Operator;
$value=$_.Value;
$newrule=New-Object Microsoft.Office.Server.Audience.AudienceRuleComponent($property,$operator,$value);
[Void]$newaud.AudienceRules.Add($newrule);
}
$newaud.Commit();
#compile audience
$args=$searchcontext.Name, "1", "1", $audname;
$runjob=[Microsoft.Office.Server.Audience.AudienceJob]::RunAudienceJob($args);
}

The audiences.xml file:

02/05/2010

Windows PowerShell Quick Reference

Filed under: PowerShell — Tags: — kctnpblog @ 10:27 am

Microsoft have released an excellent quick reference guide for PowerShell available for download here.

15/04/2010

Failed to add BusinessObjects XI SharePoint 2007 PIK to SharePoint

Filed under: SharePoint — Tags: — kctnpblog @ 11:45 pm

Whilst installing the BusinessObjects XI Portal Integration Kit for SharePoint; if the install stops with the following error:

“Failed to add BusinessObjects XI 3.1 SharePoint 2007 PIK to SharePoint. Please verify that you have all the necessary access rights and provide the correct server names, and reinstall this software.”

The following entry may also be found in the Application Event Log corresponding to this error:

Event ID: 3351
Description:
SQL database login failed. Additional error information from SQL Server is included below.
Login failed for user 'domain\userid'.

To fix this ensure that you have logged-on to the server as the SharePoint Farm Administrator before attempting the install.

09/11/2009

Enable incoming content deployment jobs on a SharePoint farm using PowerShell

Filed under: SharePoint — Tags: , — kctnpblog @ 2:24 am


cls
$spcdconfig=[Microsoft.SharePoint.Publishing.Administration.ContentDeploymentConfiguration]::GetInstance()
$spcdconfig.AcceptIncomingJobs = $true
$spcdconfig.RequiresSecureConnection = $false
$spcdconfig.Update()

03/09/2009

PowerShell in SharePoint 2010

Filed under: SharePoint — Tags: — kctnpblog @ 2:21 am

A couple of posts on SharePoint 2010 and PowerShell:

PowerShell cmdlets in SharePoint 2010

PowerShell Marches into SharePoint 2010

Dilbert on SharePoint

Filed under: SharePoint — kctnpblog @ 12:48 am

Dilbert on SharePoint

28/08/2009

Windows 7 freezing

Filed under: Uncategorized — Tags: — kctnpblog @ 4:47 am

I’m currently running Windows 7 64-bit Build 7100 on my Dell XPS M1330 and since this week have found that the computer suddenly freezes after a flicker on the screen. The only way I could recover was by cold starting. This would happen at random intervals during the day and I found that re-starting the laptop in safe mode worked perfectly fine. After a lot of trial and error I found that after changing the theme from Aero to the Windows 7 standard, the problem went away… waiting for the Windows 7 release.

15/08/2009

Set expiry policy on SharePoint list using Powershell

Filed under: SharePoint — Tags: , , — kctnpblog @ 1:51 pm

MOSS out of box functionaliy allows creating information management policies on lists to expire content on those lists. If this needs to be done using code then the following code could be used to set the expiry policy programmatically using PowerShell.
This code requires the SharePoint Powershell Profile to be loaded beforehand


#Include the additional dll references required
[Void] [System.Reflection.Assembly]::LoadWithPartialName("System")
[Void] [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Workflow")

$web=Get-SPWeb -webUrl "http://mossdev";

$list=$web.Lists["MyList"];

$listctype=$list.ContentTypes["Item"];

$policy=[Microsoft.Office.RecordsManagement.InformationPolicy.Policy]::GetPolicy($listctype);

if ($policy -eq $null) {
$policy=[Microsoft.Office.RecordsManagement.InformationPolicy.Policy]:: CreatePolicy($listctype,$null);
}

$policy.Description="Expire items the day after the expiry date";
$policy.Statement="Expire items the day after the expiry date";
$policy.Update();

$expirypolicyexists=$false;
if ($policy.Items.Count -ne 0)
{
foreach ($policyitem in $policy.Items)
{
if ($policyitem.Name -eq "Expiration")
{
$expirypolicyexists=$true;
}
}
}

if ($expirypolicyexists -eq $false)
{
$policyFeatureID=[Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration];
#set the internal field name and workflow id according to your needs
#in this case it has been set to expire the item based on the
#expiry date custom field and execute the disposition approval workflow
#when the item expires
formula
$policy.Items.Add($policyFeatureID,$customData);
$policy.Update();
"Expiry policy added"
}
else
{
"An expiry policy already exists - not overwriting";
}

$web.Dispose();

14/08/2009

Associate a workflow to a SharePoint list using Powershell

Filed under: SharePoint — Tags: , , — kctnpblog @ 1:56 am

This script will associate one of the out of the box Disposition Approval workflows to a list.
This code requires the SharePoint Powershell Profile to be loaded beforehand


#Include the additional dll references required
[Void] [System.Reflection.Assembly]:: LoadWithPartialName("System")
[Void] [System.Reflection.Assembly]:: LoadWithPartialName("Microsoft.SharePoint.Workflow")

#open the web
$web=Get-SPWeb -webUrl "http://moss";

#list to which the workflow is to be associated
$list=$web.Lists["MyList"];

#create workflow association object
$culture=new-object System.Globalization.CultureInfo("en-AU");
$basetemplate = $web.WorkflowTemplates.GetTemplateByName("Disposition Approval",$culture);
$wftasklist=$web.Lists["Workflow Tasks"];
$wfhistorylist=$web.Lists["Workflow History"];
$wfAssoc=[Microsoft.SharePoint.Workflow.SPWorkflowAssociation]:: CreateListAssociation($basetemplate,"Disposition Approval",$wftasklist,$wfhistorylist);

#associate workflow to list
$list.AddWorkflowAssociation($wfAssoc);
$list.Update();

#cleanup and end
$web.Dispose();

Older Posts »

Blog at WordPress.com.