Tag Archives: Sharepoint

Sharing service apps between farms.

See http://technet.microsoft.com/en-us/magazine/hh528474.aspx Section 8

Run this PS on both farms and exchange certs:

$rootCert = (Get-SPCertificateAuthority).RootCertificate
$rootCert.Export(“Cert”) | Set-Content D:\Certs\ConsumingFarmRoot.cer -Encoding byte
$stsCert = (Get-SPSecurityTokenServiceConfig).LocalLoginProvider.SigningCertificate
$stsCert.Export(“Cert”) | Set-Content D:\Certs\ConsumingFarmSTS.cer -Encoding byte

Then you can use Central admin (Security->Manage Trusts) to enter these in.

From the Consuming Farm, run get-farm | Select ID to get the ID of the consuming farm.

$farmID = <ID from your farm>
$security = Get-SPTopologyServiceApplication | Get-SPServiceApplicationSecurity
$claimProvider = (Get-SPClaimProvider System).ClaimProvider
$principal = New-SPClaimsPrincipal -ClaimType "http://schemas.microsoft.com/sharepoint/2009/08/claims/farmid" -ClaimProvider $claimProvider -ClaimValue $farmID
Grant-SPObjectSecurity -Identity $security -Principal $principal -Rights "Full Control"
Get-SPTopologyServiceApplication | Set-SPServiceApplicationSecurity -ObjectSecurity $security

SharePoint 2010 Session State Service

Sharepoint has two state service commands that threw me for a loop

first there is get-SPSessionStateService
then there is get-SPStateServiceApplication

Here’s an article from MSDN that talks about the differences
http://blogs.msdn.com/b/markarend/archive/2010/05/27/using-session-state-in-sharepoint-2010.aspx

In Central Admin->Manage Service Applications these show up as follows:

Get-SPSessionStateService -> shows as type “SharePoint Server ASP.NET Session State Service”
Get-SPStateServiceApplication-> shows as type “State Service” and hopfully “State Service Proxy”

While you can easily delete both from Central admin, you can create neither of them from the service applications page.

Creating a new SPStateServiceApplication (and proxy) is relatively easy: 3 lines of powershell:

# from  http://technet.microsoft.com/en-us/library/ee704548.aspx
$serviceApp = New-SPStateServiceApplication -Name ""
New-SPStateServiceDatabase -Name "" -ServiceApplication $serviceApp
New-SPStateServiceApplicationProxy -Name "" -ServiceApplication $serviceApp -DefaultProxyGroup

Creating a new SPSessionStateService, on the other hand is a little more involved…

How do I know?

I’m glad you asked….

I ran into an issue where an access report would not display because “session state is not turned on” it didn’t say which one, and through some trial and error, I now understand it was likely looking for the service returned by get-SPSessionStateService.

For me that returned a blank line with no database entry so I thought I’d be best to delete it and recreate it from scratch.

I was wrong.

While deleting and recreating the SPStateServiceApplication is easy, the SPSessionStateService was not easily done in SP2010 with the included powershell commands.

Fortunately I found this article: http://ikarstein.wordpress.com/2010/12/14/error-while-enabling-session-state-service-on-sharepoint-2010/ Which had the steps to recreate the service manually.

I enabled the ASP.Net state windows service, then followed the article above, stopping about half way through, before the provisioning part.

To Provision it, I used Enable-SPSessionStateService -DefaultProvision

Get-SPSessionStateService now returns a complete row, with a database server, and DB name, and ID and best of all Enabled = True

So to summarize my problem,
MS Access services reports needed “SPSessionStateService” which also uses the windows service “ASP.Net State Service”

In troubleshooting, I wasn’t aware of the difference between states so I deleted the “wrong” one in an attempt to reset it.
A little digging and I now have a better understanding of the issue and of the two different state services.

I hope this helps!

Simple PowerShell to Enable BLOB Cache on multiple SharePoint sites.

I needed to enable / configure BLOB caching on multiple sharepoint sites.

This is done by editing the web.config of each SharePoint site, on each SharePoint server.

I wrote this down and dirty script so I would not need to edit all the web.config’s by hand (I had about 20 web.configs to touch)

Note that since its just editing the web.config, we don’t need to run this in a SharePoint shell – I ran it from an ordinary PowerShell command prompt on my workstation.

The script:

 
Echo "Run this script under an admin account with rights to the servers being hit"
 
$dir = "\\Server\c$\inetpub\wwwroot\wss\VirtualDirectories"
$currentDate = (get-date).tostring("mm_dd_yyyy-hh_mm_ss")
# loop through each subdirectory to find each sharepoint site.
foreach ($subdir in dir $dir)
{
   #  Here In my case, all my SharePoint sites had mydomain.com as part of the folder names,
   #  So the contains statement was an easy way to only touch the web.config's of actual SharePoint sites
   #  while leaving alone central admin and other non-SharePoint websites IIS had.
 
   if($subdir.Name.Contains("mydomain.com"))
   {
        $path = $dir + "\" + $subdir.name + "\Web.config"
        echo $path
 
        $backup = $path + "_$currentDate.bak"
        $xml = New-Object XML
        $xml.Load($path)
        $xml.Save($backup)
        $element = $xml.configuration.SharePoint.BlobCache
        echo $element
        $element.location = "X:\BlobCache\14"
        $element.enabled = "true"
        $element.maxSize = "5"
        echo $element
        $xml.Save($path) 
   }
}

Sharepoint Search: Fix for Office 2007 titles not showing up properly in search results

If search results from SharePoint (not Fast) search are not showing the right title, and instead are showing a few words from the content of the document, theres a registry setting you can set to fix that.

The registry setting will be found on any machine running sharepoint search (Central admin-> Manage servers in this farm will show you which boxes have this role)

These powershell commands will show what the value is currently (or an error if its not found – a good sign that you’re on the wrong machine!)

  $RegKey ="\SOFTWARE\Microsoft\Office Server\14.0\Search\Global\Gathering Manager\"
  Cd hklm:\$RegKey 
  $key = "EnableLastModifiedOverride"
  Get-ItemProperty -path. -name $key | Select $key
  $key = "EnableOptimisticTitleOverride" 
  Get-ItemProperty -path. -name $key | Select $key

(you can see the registry entries in the code, you can edit these manually if you’d like)

This script changes the values to 0, fixing the office 2007 issue in SP2010 search:

$RegKey ="HKLM:\SOFTWARE\Microsoft\Office Server\14.0\Search\Global\Gathering Manager\"
set-ItemProperty -path $RegKey -name EnableLastModifiedOverride  -value 0
set-ItemProperty -path $RegKey -name EnableOptimisticTitleOverride -value 0

After you’re done with the above, restart the Sharepoint search service and do a full crawl – it is not necessary to reset the index.

A list of Sharepoint Virtual File paths

This will start out to be an incomplete list, but should grow with time.
These are links that are sometimes handy to have when the UI doesn’t display them.

 

 

 

Path and file explanation
_layouts/viewlists.aspx Same as site actions->View all content
_catalogs/masterpage/Forms/AllItems.aspx View master pages for this site collection.
_layouts/changesitemasterpage.aspx Changes the master page for the site collection (must be called from the site collection url, not a subweb url)
_layouts/permsetup.aspx assings the 3 magic groups to a sharepoint web called from a web or subweb url
_catalogs/lt/Forms/AllItems.aspx List template Gallery
_catalogs/solutions/Forms/AllItems.aspx Site Template (/Solutions) Gallery
_layouts/settings.aspx Site Settings
_layouts/user.aspx A list of all groups and users in a given Site
_layouts/groups.aspx A list of all groups in a given Site Collection
_layouts/AreaTemplateSettings.aspx This screen chooses what site templates are available when creating a new site in a given site collection
_layouts/quiklnch.aspx An almost odd list view of the quick launch items –
but not the one you get to from site settings.
This is linked to from the “getting started” web part.
_layouts/qlreord.aspx Same as above – this one lets you sort the quick launch items.
_layouts/AdminRecycleBin.aspx End User Recycle Bin.
_layouts/AdminRecycleBin.aspx?View=2 Deleted from End User Recycle Bin.
Pagename.aspx?contents=1 View the web parts on a page – good for times when a web part keeps a page from rendering in normal mode.

Get all sharepoint users users in the farm with Powershell to a CSV file

This is a script that gets each sharepoint site on the farm, enumerates all the site collections and webs and dumps them to the screen as well as a CSV file.

The Current date and time is always appended to the file name so you don’t have to worry about wiping out previous results.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#getalluserseverywhere
Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
 
$timestamp = get-date -format "yyyyMMdd_hhmmtt"
$filenameStart = "AllFARMUsers"
$logfile = ("{0}{1}.csv" -f $filenamestart, $timestamp)
 
$header = "type,user,group,weburl,webname"
$header | out-file -FilePath $logfile
 
$iissitelist = get-spwebapplication 
foreach($onesite in $iissitelist)
{
 
	foreach ($SiteCollection in $onesite.sites)
	{
		write-host $SiteCollection -foregroundcolor Blue	
		foreach ($web in $SiteCollection.Allwebs)
		{ 
			 write-host "    " $web.url $web.name "users:" -foregroundcolor yellow
			 # Write-host "        " $web.users | select name 
			 foreach ($userw in $web.users)
			 {
				#if ($userw -like "domain\*")
				#{
					write-host "        " $userw -foregroundcolor white
					#$msg = ("{0},{1} user:{2}" -f $web.url,$web.name, $userw)
					$msg = ("RootUser,{0},-,{1},{2}" -f $userw, $web.url,$web.name) 
					$msg | out-file -FilePath $logfile  -append
				#  }
			   }
 
 
			 foreach ($group in $web.Groups)
			{
						Write-host "        " $web.url $group.name: -foregroundcolor green
				 foreach ($user in $group.users)
				 { 
					# if ($user -like "Domain\*")
					 #{   
						  Write-host "            " $user -foregroundcolor white
						  #$msg = ("{0},{1},group:{2}, user:{3}" -f $web.url, $web.name, $group, $user)
						  $msg = ("GroupUser,{0},{1},{2},{3}" -f $user, $group, $web.url, $web.name)
						  $msg | out-file -FilePath $logfile  -append
					 #}
				 }
			}	
			$web.Dispose()
		}
 
	}
}

Remove a stuck timer job in SharePoint using Powershell

I recently had a stuck timer job in our sharepoint farm.
It seemed like an easy thing for Powershell, but it turned out to be one step more complicated – I’m not sure why, but here’s the solution I used – thanks to Todd from the Vendor I was working on for providing the fix!

We can use the Cmdlet get-SPTimerJob to see all timerjobs in our sharepoint farm.

If we add a nice little where clause, we can limit the list to a single item:

Get-SPTimerJob | where {$_.name -like "Name of your stuck job"}

Normally I’ve been able to assign the results to a variable

ie like this:

$badjob = Get-SPTimerJob | where {$_.name -like "Name of your stuck job"}

Which works.
What didn’t work however was this:

$badjob.delete()

For some reason, I got an error that there was no delete method.
Weird.

So instead:

Get-SPTimerJob | where {$_.name -like "Name of your stuck job"} |fl
# I then read the ID from the output of the above (note I added | fl at the end) 
# and I copied and pasted it into this command:
$badjobTake2 = Get-SPTimerJob -ID (pasted the ID here)
$badjobTake2.Delete()  #this worked

I’m not sure what the difference is, maybe I even fat fingered it the first time..
but that’s how it got resolved.

Enable Versions on every SharePoint Site with PowerShell (updated with logging)

The Script below will list the version status of every site in your farm.
Note that as the script is below, it only reports, you’ll need to uncomment 3 lines if you want it to make the changes.

It’s a good idea to run the script once or twice before you do that, so you have a log of what settings were.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
 
$timestamp = get-date -format "yyyMMdd_hhmmtt"
$filenameprefix = "VersionScriptoutput"
$logfile = ("{0}_{1}.csv" -f $filenameprefix, $timestamp)
 
$header = "ListURL,Enabled"
$header | out-file -filepath $logfile
 
# tip - the script as is will pull every sharepoint site (at the IIS level) in your farm.
# if you want to filter this to a single IIS site,
# remove the # from the middle of the next line and enter your site's url
 
$iissitelist = get-spwebapplication # | where {$_.url -eq "https://www.yoursite.com/"}
foreach ($iissite in $iissitelist)
{
	foreach ($SiteCollection in $iissite.sites)
	{
		write-host $SiteCollection -foregroundcolor Blue
		foreach ($oneweb in $SiteCollection.allwebs)
		{
		   write-host  $iissite.url $oneweb -foregroundcolor Green
		   #now this is is where we look at the lists
		   $lists = $oneweb.lists
		   foreach ($list in $lists)
		   {
			  if($list.EnableVersioning -eq $false)
			  {
				  write-host  $iissite.url $oneweb"/"$list"/ is a not using versions" -foregroundcolor yellow
				  $msg = ("{0}/{1},false" -f  $oneweb.url, $list.rootfolder)	
			           $msg | out-file -filepath $logfile -append
                                       # note!
                                       # if you actually want to make the changes, uncomment the next 3 lines!
				  #$list.Enableversioning = $true
				  #$List.MajorVersionLimit = 3
				  #$list.update()
			  }
			  else
			  {
				  Write-host  $iissite.url $oneweb"/"$list"/ has versions enabled! "
				  $msg = ("{0}/{1},true" -f  $oneweb.url,$list.rootfolder)				  
                                       $msg | out-file -filepath $logfile -append
			  }
		   } 
		}
	}
}

PowerShell to activate a SharePoint 2010 feature on every site collection in a web app

I recently was given a WSP to add to our farm.

In this case after the WSP was installed and deployed we needed to activate the feature at the site collection level.
Thats usually easy enough to do through the UI, but in this particular case we had a web application which had over a dozen site collections.

ie:

  • http://jack.com
  • http://jack.com/blog
  • http://jack.com/marketing
  • 10 more like the above…

Activating it at http://jack.com from the UI was fine, but when the user navigated to http://jack.com/blog they were stumbling onto another site collection, and the feature wasn’t activated there.

To activate it on every Site collection meant that I’d have to a) know what each site collection was, and b) visit that site, and activate the feature.

Too much work.

What was needed was a simple script that would loop though each site collection, enabling the feature on each one.

The script below is a result of that need…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 
 # this script enables a feature on every site collection on a given web app
 
 Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
 $webs =  get-spsite -webapplication "http://www.yoursharepointURL.com"
 $feature = "YourFeatureName" #this might not be what you expect it to be, best to do get-spfeature | Select displayname
 
  Foreach ($oneweb in $webs)
  {
    write-host $oneweb
    $siteFeature = get-spfeature -site $oneweb | Where {$_.displayname -eq $feature}
    if ($siteFeature -eq $null)
    {
      Write-Host "Activating Site level Features at $oneweb" -foregroundcolor Yellow
      Enable-SPFeature -Identity $Feature -URL $oneweb.URL -Confirm:$False
    }
    else
    {
      Write-Host "Feature $feature is already activated on $oneweb" -foregroundcolor green
    }
  }

If you look at the simple logic, you’ll see you can run it more than once – and the second time you run it, it should display an all green list indicating that all the site collections already have the feature activated.

Powershell to test a URL against UAG rulesets

Many companies use Microsoft Forefront Universal Access Gateway (UAG) to publish sharepoint sites to the public internet.

We recently had a problem where office (word, excel, powerpoint) documents would not open through a sharepoint published site Via UAG in the office app on the end users home PC.

In UAG there’s a bunch of rules that match the URL in question via a regex.
We needed a quick way to test our URL against the regex in each and every rule so we knew which rules applied.

There currently isn’t a way to do that in UAG (there should be)
So as an alternate to doing these manually, I used the “Export rules” feature, then wrote the following powershell script to parse the exported file, gather the RegEx’s of each, and test the URL in question against each RegEx so you can see what rule is actually being applied.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# if you run from ISE and get a permissions error copy and paste everything to a new tab.
# or run get-executionpolicy (take note what it is) then run (as an administrator): set-executionpolicy unrestricted
#set theses two variables -
$ExportedRuleSetFile = get-content 'c:\PS\PRD_URLset.txt'
$URLtoFind = "/get/content/from/sharepoint.aspx"
Function FindAMatch($Rulefile, $URL)
{
	$table = New-Object system.Data.DataTable "RegExList"
	$col1 = New-Object system.Data.DataColumn Section,([string])
	$col2 = New-Object system.Data.DataColumn Name,([string])
	$col3 = New-Object system.Data.DataColumn RegEx,([string])
	$table.columns.add($col1)
	$table.columns.add($col2)
	$table.columns.add($col3)
 
	$row = $table.NewRow()
	$row.Section = "Section"
	$row.name = "Name"
	$row.RegEx = "Regex"
 
	foreach ($line in $Rulefile )
	{
		if ($line[0] -eq "[")
		{
			$table.Rows.add($row)
			$row = $table.NEwRow()
			$row.Section = $line
		}
		elseif ($line.substring(0,7) -eq "m_regex")
		{
			$row.RegEx = $line.substring(8)
		}
		elseif ($line.substring(0,7) -eq "m_name=")
		{
			$row.Name = $line.Substring(7)
		}
	}
	$table.Rows.add($row)
 
	write-host Note: this only searches SharePoint Rules
	# note the select statement is needed because many of the records don't have regex values
	foreach ($record in $table.select("name like 'SharePoint%'"))
	{
		if ($url -match $record.regex)
		{
			Write-host $url found in $record.name via regex matching $record.regex
		}
	}
} #end function
FindAMatch $ExportedRuleSetFile $URLtoFind

Sample output looks like this:

Note: this only searches SharePoint Rules
/get/content/from/sharepoint.aspx found in SharePoint14AAM_Rule1 via regex matching (/[^"#&amp;*+:&lt;&gt;?\\{|}~]*)/?
/get/content/from/sharepoint.aspx found in SharePoint14AAM_Rule47 via regex matching (/[^"#&amp;*+:&lt;&gt;?\\{|}~]*)*/[^"#&amp;/:&lt;&gt;?\\{|}~]*\.aspx
/get/content/from/sharepoint.aspx found in SharePoint14AAM_Rule48 via regex matching /
/get/content/from/sharepoint.aspx found in SharePoint14AAM_Rule60 via regex matching (/[^"#&amp;*+:&lt;&gt;?\\{|}~]*)/?

As a side note, we were able to pinpoint the rule that applied to our URL which made fixing it much easier!

Sharepoint 2010 ULS logs – How to keep them in SQL

This is another “Wow that was easy!” SharePoint items…

Open Central Admin
Go to the Monitoring section, then under “Timer Jobs”, select “Review job definitions”

There’s a timer job called “Diagnostic Data Provider: Trace Log”

It’s disabled by default, enable it and it will create new tables and a view on your logging database. (I think by default this is named WSS_Logging)
Leave it enabled (mine is set to run every 10 minutes)

Open SQL server Management studio and connect to your sharepoint DB server.
expand the WSS_Logging DB
Expand Views
Look for the new view called “ULSTraceLog”

I usually right click on the view name and “Select Top 1000 Rows”
Then from there I can add a where clause to the query thats on screen,
most often it’s
WHERE CorrelationID = ‘abcd-efg-hijk-lmnop-qrstuv’

Another tip- in the results (which on my system default to the “grid” view),
Right Click, Select All, then
Right Click, Copy with headers
you can then paste this into Excel and it’s pretty readable if you need to email it to someone.

As a side note, I’ve enabled this on a handful of farms and it seems to auto trim the DB sizes – so you don’t need to worry about the DB filling up over time.

Powershell script to add a list of users to the site collection administrators group of every site on your SharePoint 2010 farm.

I wanted a way to inject myself as a site collection admin into every site in sharepoint, Note, I’m not talking about the primary/secondary that you can set in Central admin.
I’m talking about that group you can only get to from within each site itself. Or in this case, with the powershell script below…
Note that it takes an array of names – if you have a team of admins or developers that all need access, you can put all their names in the list.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# set site collection owner for all sites...
# 1-2012
Add-PSSnapin Microsoft.SharePoint.PowerShell
 
# $AccountList is an array of Windows Identities in the format of $AccountList = @("DOMAIN\USERID" , "DOMAIN\USERID2")
$AccountList = @("LAB\Jack", "Lab\tom", "Lab\dick", "lab\harry")
 
#this gets an array of objects representing the sites at the IIS level:
$IISSites = Get-SPWebApplication
Foreach($oneIISSite in $IISSites)
{
   #using .Sites, we can get a list of the site collections
   foreach ($SharepointSiteCollection in $oneIISSite.Sites)
   {
      write-host $SharepointSiteCollection.url -ForegroundColor Cyan
      $spweb = Get-SPWeb $SharepointSiteCollection.url
 
      #now we have the website, so lets look at each account in our array
      foreach ($Account in $AccountList)
      {
         #lets see if the user already exists
         Write-host "Looking to see if User " $account " is a member on " $SharepointSiteCollection.url -foregroundcolor Blue
         $user = Get-SPUSER -identity $Account -web $SharepointSiteCollection.url -ErrorAction SilentlyContinue #This will throw an error if the user does not exist
         if ($user -eq $null)
         {
            #if the user did NOT exist, then we will add them here.
            $SPWeb.ALLUsers.ADD($Account, "", "", "Added by AdminScript")
            $user = Get-SPUSER -identity $Account -web $SharepointSiteCollection.url
            Write-host "Added user $Account to URL $SPWeb.URL" -Foregroundcolor Magenta
         }
         else
         {
            Write-host "user $Account was already in URL " $SPWeb.URL -Foregroundcolor DarkGreen
         }
         if ($user.IsSiteAdmin -ne $true)
         {
            $user.IsSiteAdmin = $true
            $user.Update()
            Write-host "$account has been made an admin on $SPWeb.URL" -Foregroundcolor Magenta
         }
         else
         { 
         Write-host "$account was already an admin on $SPWeb.URL" -Foregroundcolor DarkGreen
         }
     }
     $SharePointSiteCollection.Dispose()
}
}

 

Here’s another version of the script, this one also takes an array of top level URL’s

It’s handy if you have lots of url’s on your site and only want to work with a few of them.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# set site collection owner for all sites...
# 2-2013 Jack
 
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$logfile = "Powershelloutput.log"
 
# $AccountList is an array of Windows Identities in the format of $AccountList = @("DOMAIN\USERID" , "DOMAIN\USERID2")
$AccountList = @("domain\tom", "domain\dick", "domain\harry")
 
# $iisSiteList is an array of top level IIS site URLs
$iisSiteList = @("http://site1.yoururl.com", "http://anothersite.yoururl.com")
 
# this is from an earlier version of the script
# That scrip looks at all SP sites on the farm, I've left the old code here for reference
# this gets an array of objects representing the sites at the IIS level:
##  $IISSites = Get-SPWebApplication
 
Foreach($oneIISSite in $IISSiteList)
{
  #using .Sites, we can get a list of the site collections
  #so really what were saying is for each SharepointSiteCollection
 
  #this code is altered a bit, since we're using an array of top level site names.
  # we need to use (Get-SPWebApplication $oneIISSite).Sites
  # which is the same as $sitelist = Get-SPWebApplication $oneIISSite
  #                      $sitelist.sites
  foreach ($SharepointSiteCollection in (Get-SPWebApplication $oneIISSite).Sites)
  {
       $msg = $SharepointSiteCollection.url
       write-host  -ForegroundColor Cyan $msg
       Add-Content $logfile $msg
 
       $spweb = Get-SPWeb $SharepointSiteCollection.url
 
       #now we have the website, so lets look at each account in our array
       foreach ($Account in $AccountList)
       {
           #lets see if the user already exists  
           $msg = "Looking to see if User " + $account + " is a member on " + $SharepointSiteCollection.url
           Write-host -foregroundColor Blue $msg
           Add-Content $logfile $msg
 
           $user = Get-SPUSER -identity $Account -web $SharepointSiteCollection.url -ErrorAction SilentlyContinue #This will throw an error if the user does not exist
           if ($user -eq $null)
           { #if the user did NOT exist, then we will add them here.
               $SPWeb.ALLUsers.ADD($Account, "", "", "Added by AdminScript")
               $user = Get-SPUSER -identity $Account -web $SharepointSiteCollection.url        
               $msg = "Added user $Account to URL $SPWeb.URL"
               Write-host -Foregroundcolor Magenta $msg
               Add-Content $logfile $msg
           }
            else
           {
                $msg = "user $Account was already in URL " + $SPWeb.URL 
                Write-host -ForegroundColor DarkGreen $msg
                Add-Content $logfile $msg
           }
 
           if ($user.IsSiteAdmin -ne $true)
           {
             $user.IsSiteAdmin = $true
             $user.Update()
             $msg = "$account has been made an admin on $SPWeb.URL"
             Write-host  -Foregroundcolor Magenta $msg
             Add-Content $logfile $msg
           }
           else
           {
             $msg = "$account was already an admin on $SPWeb.URL" 
             Write-host -ForegroundColor DarkGreen $msg
             Add-Content $logfile $msg
 
           }
       }      
 
     $SharepointSiteCollection.Dispose()
  }
 } 
$msg = "=============== ALL DONE ================"
Write-host -ForegroundColor DarkGreen $msg
Add-Content $logfile $msg

 

PDF’s not opening in browser from a sharepoint 2010 site?

I had this problem enough times that I wanted to capture the solution.

First of all, credit goes to Craig Lussier on the Technet forms, his post has the full solution and background.

http://social.technet.microsoft.com/Forums/en-US/sharepoint2010setup/thread/2f66404e-5193-46d3-b6b1-45cf72410432?prof=required

I used the above solution and it worked great.

I also found a script that I did not try. The script is described as being able to change this setting system wide by looping through each document library in each subsite of a given site – it could come in handy. (the script is by the same poster – Craig Lussier – Thanks Craig!

http://gallery.technet.microsoft.com/scriptcenter/Set-SPDocumentLibrary-0426781c

The code below is from the first link above, I’ve copied it here in case MS ever changes the link structure and the original post can’t be found. 

# SPAssignment
$gc = Start-SPAssignment

#Get Web
$web = $gc | Get-SPWeb "http://yourspweburl"

#Get Document Library
$docLib = $web.lists["Your Document Library Title"]

#View all properties/methods of the Document Library and you'll see that BrowserFileHandling is a property
$docLib | Get-Member

#See the current BrowserFileHandling setting for the Document Library
$docLib.BrowserFileHandling

#If you need to change it from Strict to Permissive
$docLib.BrowserFileHandling = "Permissive"
$docLib.Update()

# End SPAssgment
$gc | Stop-SPAssignment

Scope Sharepoint FAST search to a file share

Ok this took a bit of wrangling and some new understandings on my part to understand.

I was trying to index a file share of content, and create a FAST search page that would ONLY search that content. Since the FAST server had tons of other stuff on it, I needed to create a scope to narrow down the search. 

I used this powershell command to create the scope – this is key – you can’t do this from the sharepoint GUI (As of Sharepoint 2010 SP)

New-SPEnterpriseSearchQueryScope -SearchApplication “FAST Search Query SSA” -Name thisisthescopename -Description “A scope for a file share” -DisplayInAdminUI 1 -ExtendedSearchFilter “contentsource:nameofcontentsource”

Some explanation – the -SearchApplication is the name of our FAST query SSA – yours might be named differently

The -ExtendedSearchFilter nees some explanation,

First, the word contentsource needs to be in lower case – I had orignally tried it in mixed case (ContentSource) and that didn’t work

Next, the :nameofcontentsource – this is the artificial name you gave the content source over in your FAST Content SSA – it’s NOT the URL, UNC Path etc.. of the content!

for example, if in your FAST Content SSA, you created a content source on \\server1\files and called it myfiles

then your ExtendedSearchFilter would look like this: “contentsource:myfiles”

Ok so that’s the end of my explanation of the command itself.

After a few minutes the scope is created and we can test it in a normal FAST search site in sharepoint

Lets say that we indexed a bunch of content on monkeys and we want to see if it turns up in our new scope.

We would search for scope:thisisthescopename monkey

If we get the results we want, then we know the scope is working.

One step beyond this, we can create a special search page for this scope,

create a new FAST search site in sharepoint.

do a bogus search on the sites home page so that it shows you the results page

Edit the results page in the browser

find the web part at the bottom that displays the results

edit that web part

On the right hand side of the page, are the web parts properties, one of them is ‘scope’

put thisisthescopename in that web part and save the page (don’t forget to check in/publish if needed too)

now on your newly modified search page, when you enter a search for monkey, it will limit it to your scope.

Clear FAST Search Content Collection

I had a stubborn FAST Server installation that continued to return search results, even after the content source was removed from FAST!

After stumbling around, someone on the FAST forums at Microsoft suggested clearing the sp collection, but didn’t say how.

Here’s how:

On the fast server, there will be a shortcut to launch a FAST powershell prompt – open that

Enter the command

Clear-FastSearchContentCollection sp

That should clear it out – you’ll need to do full crawls on all your content sources after this is done to repopulate the index, so it’s best not to do this to a production box without understanding how long search will be down.

Also note that in FAST Search for Sharepoint, pretty much everything is stored in the SP collection – It’s my understanding that as of right now, you can only have one collection in FAST for SP.

Snippet of XSLT to create a link to the parent folder of an item in a search result

I wanted to add a link to the parent folder of an item in FAST search results.

I had found an article that said I could use the “SiteName” property.

Unfortunately, this content wasn’t from a SharePoint site, it was from a File Share.

The “SiteName” only returned \\Server\Sharename for each result, never the folder path

For example \\Server\Share\Folder1\SubFolderA\myfile.txt is where the file is

SiteName retured \\Server\Share

I wanted \\Server\Share\Folder1\SubFolderA\

The following XSLT uses a few chained string commands to return the desired results

<xsl:if test="isdocument = 'True'">
   <br/>
   <a>
      <xsl:attribute name="href">
         <xsl:value-of select="substring(url,1,string-length(url) - string-length(title))"/>
      </xsl:attribute>
      <i>Link to Containing Folder</i>
   </a>
</xsl:if>

Snippet of XLST to dump the output of search results

This is one of those posts more to serve as a reminder to me than anything.

While watching a video on SharePoint-Videos.com about customizing search results with XSLT, the presenter showed how to use a small bit of XSL to dump all the search results returned by the search engine – the original video can be found here: http://www.sharepoint-videos.com/sp10-customize-search-results-using-xslt/

 

<?xml version=”1.0″ encoding=”UTF-8″>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xls:template match "/">
<textarea rows="20" cols="100">
 <xsl:copy-of select="*"/>
</textarea>
</xsl:template>
</xsl:stylesheet>

Using Visifire Charts in Sharepoint with SQL data – Part 1

Visifire.com has a nice silverlight charting library that does animated charts and graphs.

My employer was looking to do up a Dashboard in SharePoint and I used Visifire, the Sharepoint Content Editor Web part and a few back end aspx pages to grab data from various sql servers to present the graphs.

I’m doing a video series on the basics of how to do it.

This first video introduces visifire, downloads some samples and walks through getting the sample to work locally on your PC.

Part 2 will discuss the Visifire Chart Designer.
Part 3 will show how to copy the needed files to SharePoint and how to put the relevant HTML in a SharePoint Content Editor WebPart.
Part 4 talks about how to move Source XAML to a separate file.
Part 5 talks about one way to construct a back end ASPX page to produce the XAML and feed it back.
Part 6 talks about how to modify the ASPX page to query a database and produce live data
Part 7 talks about how to move that page onto the SharePoint Server.