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
$AUDIENCEJOB_START = '1'  
$AUDIENCEJOB_INCREMENTAL = '0'  
[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)
$userprofile.CreatePersonalSite();

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:

[Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges()
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.







Friday, April 20, 2012

Amazon EC2 Powershell

I keep forgetting where to find the latest and somehow never use the right search terms. So, here is the location of the Amazon EC2 API Tools which include the Powershell cmdlets
http://aws.amazon.com/developertools/351

And for completeness, the AWS toolkit is here: http://aws.amazon.com/sdkfornet/

And now for Windows is here: http://aws.amazon.com/powershell/

Friday, March 2, 2012

My Site creation failure ... System.ArgumentException: Another site already exists ...

My users were going to their My Content area for the first time (ie: creating their personal site) and got the following error:
There has been an error creating the personal site. Contact your site administrator for more information
Checking the ULS, I see the following:

My Site creation failure for user '[some-user]' for site url '[some-site]'. The exception was: Microsoft.Office.Server.UserProfiles.PersonalSiteCreateException: A failure was encountered while attempting to create the site. ---> System.ArgumentException: Another site already exists at [some-site]. Delete this site before attempting to create a new site with the same URL, choose a new URL, or create a new inclusion at the path you originally specified.    


It turned out that my Personal Site Location had been changed from "my/personal" to just "my" so it was not pointing at a wildcard inclusion managed path.

Wednesday, February 1, 2012

SPListItem provided is not compatible with a Publishing Page

I have been hitting my head against a wall lately with a custom master page and some custom sites. There appears to be an incompatibility between the 2. Since they come from separate sources, finding out where to point the finger is a little tricky. My custom master page makes use of Publishing, Feature Stapling, among other things.

The behaviour is that when I edit a community page and then click publish, it would throw an exception

System.ArgumentException: Invalid SPListItem. The SPListItem provided is not compatible with a Publishing Page.   
 at Microsoft.SharePoint.Publishing.PublishingPage.GetPublishingPage(SPListItem sourceListItem)    
 at Microsoft.SharePoint.Publishing.Internal.WebControls.PublishingPagePublishHandler.RaisePostBackEvent(String eventArgument)    
 at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)    
 at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

I have yet to figure out what is going on here. However here are some other observations

$web = Get-SPWeb <SPWeb URL>
[Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($web)

This returns false despite the Publishing tab being there and the SharePoint Server Publishing site feature is activated.


So, ignoring the False, I continue with this:
$publishingweb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$publishingpages = $publishingweb.GetPublishingPages()

This throws an exception:

Exception calling "GetPublishingPages" with "0" argument(s): "The site is not valid. The 'Pages' document library is missing."
At line:1 char:53
+ $publishingpages = $publishingweb.GetPublishingPages <<<< ()
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

... but the Pages document library does indeed exist and I do have administrative rights on it.


I also try the following:

$pages = $web.Lists | Where-Object {$_.Title -eq "Pages"}
$page = $pages.Items | Where-Object {$_.Name -eq "default.aspx"}
[Microsoft.SharePoint.Publishing.PublishingPage]::IsPublishingPage($page)

... and get False which I would expect given the results from above. What doesn’t make sense is that this default.aspx page does have a Publish tab on it.

I then decided to try the IsPublishingWeb again, but without the custom master page. This is still giving me False. So, I guess I will start pointing the finger towards my custom site ...




Tuesday, January 3, 2012

Blog spammers, get lost

I got a few spam comments lately that appear to be either attempts to link to questionable sites or attempts to do some SEO on their own site.

The latest is crafted to semi legitimate
Thanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write ups thanks once again

In general, I prefer openness, but will not tolerate this kind of activity. As a result, I have changed my comment settings. Hopefully, these buggers will go away. 

Friday, December 23, 2011

Trying to configure FAST search and SharePoint Search to work on the same web application

I have been trying to run FAST search for my content and standard SharePoint Search for people search. I know FAST can do people search, but a third party application is forcing my hand.
I believe I have run into a wall as it appears that the OOTB search web parts do not allow you to pick one search over the other and the Configure Service Application Associations only lets you pick down to the granularity of the service application.
Incidentally, if I do not have FAST Search Query Service Application set as default in my Configure Service Application Associations, my FAST Search Center will return an error "The search request was unable to connect to the Search Service"

Oh well, time to give up and move on.