Archive for June, 2012

During, a recent project I had to create Term Stores automatically by using PowerShell.  In SharePoint you can save TermStores in .csv files and upload them with the GUI, so If it can be done with the GUI, there’s always a way to do it in PowerShell.   After some searches on Google, I found the TechNet article ( that explains the format in which the .csv file must be. However a small mistake can mess everything up.

Luckily, I found this great Excel Macro on the Web done by Wictor Wilén.  

When you’re done writing all your metadata, just click the “Create Term Store File”.  The excel macro does it for you in a .txt. However, I changed the extension to .csv to make sure that it works well with SharePoint.

Now, here is the code to import it into SharePoint.

function ImportTermSet([Microsoft.SharePoint.Taxonomy.TermStore]$store, [string]$groupName, [PSCustomObject]$termSet) {  
  function ImportTerm([Microsoft.SharePoint.Taxonomy.Group]$group, 
                      [string[]]$path) {        
    if ($path.Length -eq 0) {
    } elseif ($group -eq $null) {
      $group = $store.Groups | where { $_.Name -eq $path[0] }
      if ($group -eq $null) {
        $group = $store.CreateGroup($path[0])
    } elseif ($set -eq $null) {
      $set = $group.TermSets | where { $_.Name -eq $path[0] }
      if ($set -eq $null) {
 Write-Host “Create $path[0]”
        $set = $group.CreateTermSet($path[0])
Write-Host “Created $path[0]”
    } else {
      $node = if ($parent -eq $null) { $set } else { $parent }
      $parent = $node.Terms | where { $_.Name -eq $path[0] }       
      if ($parent -eq $null) {
        $parent = $node.CreateTerm($path[0], 1033)
    ImportTerm $group $set $parent $path[1..($path.Length)]                                     

  $termSetName = $termSet[0].”Term Set Name”    
  $termSet | where { $_.”Level 1 Term” -ne “” } | foreach {
    $path = @($groupName, $termSetName) + @(for ($i = 1; $i -le 7; $i++) { 
      $term = $_.”Level $i Term”
        if ($term -eq “”) {
        } else {
    ImportTerm -path $path

$url = “http://vlad.test.loc”

$session = Get-SPTaxonomySession -Site $url
$store = $session.TermStores[“Managed Metadata Service”]   
$termSet = Import-Csv “C:Vladmetameta1.csv”
ImportTermSet $store “vladcatrinescublogtermstore” $termSet

Start-Sleep -Seconds 10; 
Say Thanks if it helped. 

No ratings yet.

Please rate this

I recently used a PowerShell Script to Deploy a Custom .wsp solution in the Solution Gallery and activate it.

However, when running the Install-SPUserSolution command I had this error: Install-SPUserSolution :  Unable to load assembly group. The user assembly group provider threw an exception while trying to provide user assemblies for the specified assembly group.

Inner Exception: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.     at Microsoft.SharePoint.SPListItemCollection.get_Item(Int32 iIndex)     at Microsoft.SharePoint.Administration.SPSolutionLanguagePack.GetSolutionInfoFromGallery(Guid siteId, Guid solutionId, String solutionHash, String& fileName, String& hash, Byte[]& fileBytes)     at Microsoft.SharePoint.UserCode.SPUserCodeLightweightSolutionAssemblyGroupProvider.GetAssembliesInGroup(Guid siteId, String assemblyGroupI…               

06/13/2012 08:26:25.57*               SPUCHostService.exe (0x06A0)                 0x025C  SharePoint Foundation                 Sandboxed Code Service                      fe66       Medium               …d)     at Microsoft.SharePoint.UserCode.SPUserCodeAssemblyCacheManager.EnsureUserCodeAssemblyGroupIsCached(Guid siteId, SPUserCodeAssemblyGroupId userCodeAssemblyGroupId)

The Fix:

In the WebApplication UserPolicy, add  the Service Account used for  “Microsoft SharePoint Foundation  Sandboxed Code Service”  with “Full Control” rights.  

This should fix the problem.

No ratings yet.

Please rate this

When installing a new SharePoint server, sometimes it doesn’t let you access your SharePoint sites from your SharePoint server. In order to fix this, you can either add the key manually, or do it by PowerShell which is a lot faster :).

#Vlad Catrinescu
Write-Host -ForegroundColor White " - Disabling Loopback Check..."

$LsaPath = "HKLM:\System\CurrentControlSet\Control\Lsa"
$LsaPathValue = Get-ItemProperty -path $LsaPath
If (-not ($LsaPathValue.DisableLoopbackCheck -eq "1"))
New-ItemProperty HKLM:\System\CurrentControlSet\Control\Lsa -Name "DisableLoopbackCheck" -Value "1" -PropertyType dword

Say thanks if it helped 🙂

5/5 (1)

Please rate this

Here is a little script that lets you configure SharePoint Outgoing Email Settings using Power Shell.

#Vlad Catrinescu
$SMTPServer = “”

$EmailAddress = “svcfarm@vlad.loc”
$ReplyToEmail = “svcfarm@vlad.loc”

Write-Host -ForegroundColor White ” – Configuring Outgoing Email…”
$loadasm = [System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
$SPGlobalAdmin = New-Object Microsoft.SharePoint.Administration.SPGlobalAdmin
$SPGlobalAdmin.UpdateMailSettings($SMTPServer, $EmailAddress, $ReplyToEmail, 65001)
Write-Host “Failed”

Say Thanks if it helped 🙂

No ratings yet.

Please rate this

Here is a little script on how to Disable IE Enhanced Security Using PowerShell

#Vlad Catrinescu
Write-Host -ForegroundColor White ” – Disabling IE Enhanced Security…”
Set-ItemProperty -Path “HKLM:SOFTWAREMicrosoftActive SetupInstalled Components{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}” -Name isinstalled -Value 0
Set-ItemProperty -Path “HKLM:SOFTWAREMicrosoftActive SetupInstalled Components{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}” -Name isinstalled -Value 0
Rundll32 iesetup.dll, IEHardenLMSettings,1,True
Rundll32 iesetup.dll, IEHardenUser,1,True
Rundll32 iesetup.dll, IEHardenAdmin,1,True
If (Test-Path “HKCU:SOFTWAREMicrosoftActive SetupInstalled Components{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}”) 
Remove-Item -Path “HKCU:SOFTWAREMicrosoftActive SetupInstalled Components{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}”
If (Test-Path “HKCU:SOFTWAREMicrosoftActive SetupInstalled Components{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}”)
Remove-Item -Path “HKCU:SOFTWAREMicrosoftActive SetupInstalled Components{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}”

#This doesn’t always exist
Remove-ItemProperty “HKCU:SOFTWAREMicrosoftInternet ExplorerMain” “First Home Page” -ErrorAction SilentlyContinue

Say thanks if it helped 🙂

5/5 (1)

Please rate this

When you want to do a big script in PowerShell, sometimes it keeps asking you for confirmation even if you did not put the “-Confirm” parameter in your command.

The answer is simple, just add  -Confirm:$false

Remove-SPWebApplication $mainurl -DeleteIISSite -RemoveContentDatabases -Confirm:$false

Say thanks if it helped 🙂

No ratings yet.

Please rate this

There are some rare SharePoint cases where your SharePoint can send alerts to Users but doesn’t want to send anything to Distribution Groups.

If your SharePoint sends emails to users it means that your SharePoint outgoing email is well configured. The problem actually comes from Exchange.

Go into Exchange Management Console>  Recipient Configuration > Distribution Groups.

Right-click the Distribution Group that doesn’t work, and go into Properties. Than go into Mail Flow Settings, and go into the Properties of Message Delivery Restrictions.

You have to un-check the “Required that all senders are authenticated” check box.

Now your SharePoint will be able to send emails to that distribution group.

Say Thanks if it helped :).

5/5 (1)

Please rate this

When you deploy .wsp solutions and  you script your “Add-SpSolution  and Install-SpSolution”  in a row, PowerShell might throw an error because the Solution didn’t finish uploading on the farm before you try to activate it.

Here is a example of a do-while loop to make sure that the solution you are adding is fully uploaded and ready to be deployed before deploying it.

If you use farm solutions, use SPSolution instead of SpUserSolution

$mainurl = “http://vlad.test.loc”
Write-Host -ForegroundColor White ” – Adding and Installing vladsolution…” -NoNewline
Add-SPUserSolution -LiteralPath C:solutionsvladsolution.wsp -Site $mainurl
$ErrorActionPreference = “silentlycontinue”
Write-Host “.” -NoNewline -ForeGroundColor White;
Start-Sleep -Seconds 5;
$testsolution = Get-SPUserSolution -Identity  vladsolution .wsp -Site $mainurl

$ErrorActionPreference = “stop”
Install-SPUserSolution -Identity  vladsolution .wsp -Site $mainurl
Write-Host -ForegroundColor GREEN “Done.” 

Say Thanks if it helped 🙂

No ratings yet.

Please rate this

Before you run a SharePoint script to do anything, it’s always good to check if all the required SharePoint services are running.  However, we often forget to do that, and when we get deployment errors, it takes awhile to find out that the timer service did not start.

Here is a script that you could put at the beginning of your SharePoint scripts, that tells you if the services are running, and lets you confirm before continuing the script.

#Script to Check if SharePoint Services are running.

$ErrorActionPreference = “stop”
$sandbox = Get-WmiObject win32_service | Where-Object {$ -eq “SPuserCodeV4”}
$timer =  Get-WmiObject win32_service | Where-Object {$ -eq “SPTimerV4”}
$Trace = Get-WmiObject win32_service | Where-Object {$ -eq “SpTraceV4”}
if ($sandbox.State -eq “Stopped” -or $timer.State -eq “Stopped” -or $Trace.State -eq “Stopped” )
throw “A SharePoint Service is not running” 
Write-Host -ForegroundColor GREEN “All services  running”
Write-Host -ForegroundColor White $ “is running with” $sandbox.StartName 
Write-Host -ForegroundColor White $ “is running with” $timer.StartName 
Write-Host -ForegroundColor White $ “is running with” $Trace.StartName 
Write-Host -ForegroundColor Yellow “If everything is OK, press any key to continue. Else, Exit the script”
$x = $host.UI.RawUI.ReadKey(“NoEcho,IncludeKeyDown”)

Here is how it looks when all the services are running.   It tells you everything is running and also the service accounts they’re running under.

Here’s the error it throws when a service is not running.

Say thanks if it helped

No ratings yet.

Please rate this

I recently came across Unknown SQL Exception 297 in the Event Viewer in two of my SharePoint Deployments.   One with SQL 2012 and one with SQL 2008 R2.

Here is the full error message.

Unknown SQL Exception 297 occurred. Additional error information from SQL Server is included below.The user does not have permission to perform this action.

Event ID: 5586
Luckily, this error is pretty easy to repair. You have to grant the “View server state” permission to the farm account on the database.  Here is How you do it on both servers 

SQL Server 2008R2

1. Open SQL Management Studio and login to the instance where your SharePoint is installed.
2. Go in the Database Properties
3.  Go to Permissions and Select your Farm Account. 
4. Find the Permission “View Server state” and check the “grant” checbox
5. Click OK.  If you want to make sure that the permissions applied, just go on the tab called “Effective” and you should see the permission at the end of the list.
SQL Server 2012

1. Open SQL Management Studio and login to the instance where your SharePoint is installed.
2.  Open the Security Tab, Select your Farm account and click Properties.
3. Go in the Securables Section, Scrolldown and you will see the “VIEW Server State” , check “grant”

4. Click OK.

Uknown SQL Exception297 should stop appearing in your Event Viewer. 

If this was helpful, say thanks in the comments :). 

No ratings yet.

Please rate this