Wednesday, May 30, 2012

Unable to find type [Parameter]: make sure that the assembly containing this type is loaded

Just learning about parameters in Powershell and came across this error:
Unable to find type [Parameter]: make sure that the assembly containing this type is loaded

Yes, I am running Powershell v2.0 and no I did not easily find any reference to this in my searches.

Through some trial and error, I figured out that in my Param() declaration, I had this:
[String] $Description

The "[Parameter]" declaration was the culprit. My other ones had [Parameter(Mandatory=$true)]. So, I just removed the line and all works fine again.

Friday, May 25, 2012

Datasheet view is not supported on 64-bit versions of Office 2010

I just got a new laptop with a decent amount of memory. It also has a 64-bit version of Office 2010. I noticed that my SharePoint lists would no longer allow me to view in Datasheet view with the following error returned:
The list cannot be displayed in Datasheet view for one or more of the following reasons:
A datasheet component compatible with Microsoft SharePoint Foundation is not installed.
Your web browser does not support ActiveX controls.
A component is not properly configured for 32-bit or 64-bit support

Doing some further research I came across this:

You cannot view a list in Datasheet view after you install the 64-bit version of Office 2010
The best part is: If your business needs do not require you to use the 64-bit version of Office 2010, we recommend that you uninstall the 64-bit version of Office 2010 and install the 32-bit version of Office 2010. A 32-bit version of the Datasheet component is installed with the 32-bit version of Office 2010.

There is a workaround which is to install 2007 Office System Driver: Data Connectivity Components
However, that has implications such as needing to uninstall and reinstall this should you need to add more components to Office 2010. That sounds like a disaster waiting to happen.


Wednesday, May 16, 2012

Remove site groups

I regularly create webs and subwebs with non-inherited permissions. This results in a bunch of permissions groups created for those webs. For some reason, deleting the web does not remove the corresponding groups. Since sometimes there are a lot, I decided to write a script to do this:

$web = Get-SPWeb <URL of root web>
$groupstodelete = $web.SiteGroups | Where-Object {$_.Name -eq "<whatever matching criteria>"}
$groupstodelete | ForEach-Object {$web.SiteGroups.Remove($_.Name)}

Simple and saves me a lot of clicking

Monday, May 14, 2012

Compiling all audiences

I have a Powershell script that adds users and wanted it to also compile audiences. I thought this would have been under on of the UserProfileManager or the UserProfileConfigManager classes. However, it appears that it is only available under the RunAudienceJob static member of the Microsoft.Office.Server.Audience class. Fortunately, it is fairly straightforward to execute:

$applicationId = (Get-SPServiceApplication -Name 'User Profile Service Application').Id
[Microsoft.Office.Server.Audience.AudienceJob]::RunAudienceJob(@($applicationId, $AUDIENCEJOB_START, $AUDIENCEJOB_INCREMENTAL))

... with some inspiration from: SharePoint 2010 Compile All Audiences 

Thursday, May 10, 2012

Automatically creating My Site personal site

A user's My Site personal site is automatically created the first time they click on the My Content link. However, for other reasons, I need to have these personal sites already created before they log in. As a result I went looking for a script to do this.

Here is essentially what I tried:

$URL = "http://someurl"     
$accountName = "myuser"

$site = New-Object Microsoft.SharePoint.SPSite($URL) 
$context = [Microsoft.Office.Server.ServerContext]::GetContext($site) 
$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context) 

$userprofile = $upm.GetUserProfile($accountName)

This was not successful in creating the personal site.

The account under which I run this has administrator rights on the User Profile Service Application, and is in the Farm Administrators Group. In the ULS there was an entry for "Access Denied". I also do have Self Service Site Creation enabled.

Seeing as this was an "Access Denied" I then tried to run the script as the SharePoint Farm Account. This was successful. Unfortunately, I do not want to run this script as the Farm Account.

Next step was to try running this with elevated privileges which involved putting my code within this:

Still no luck

Next was to try using a different user token like this:
$site = New-Object Microsoft.SharePoint.SPSite("myurl", [Microsoft.SharePoint.SPUserToken]::SystemAccount)
or even with the user account for which I am creating the personal site.
Still no luck.

At this point, I gave up and put my script into the Task Scheduler to be executed as the Farm Account.

It would be nice to know exactly what permission is missing.