Error during farm config: New-SPConfigurationDatabase failed with exception “The process does not passess the ‘SeSecurityPriviledge’ priviledge which is required for this operation.”

Today I tried to configure a new SharePoint farm. I got this error:

image

“The process does not passess the ‘SeSecurityPriviledge’ priviledge which is required for this operation.” – Although the account used to configure SharePoint is local administrator!!

After searching the internet I found that issue and a solution for that.

Check the Local Group policy or the Domain Group Policy and validate the Setting

Computer Configuration => Policies => Windows Settings => Security Settings => Local Policies => User Rights Assignments => Manage auditing and security log

image

If this setting is defined the account that is used to install SharePoint needs to be member of this setting. – Just add the account or the “local administrators” (“.Administrators”) group.

How to install SharePoint Server 2010 Language Pack SP1.

When you install SharePoint Server 2010 by using the official slipstreamed version that includes SP1 you may get an error while installing SP1 for several language packs.

“The expected version of the product was not found on the system – Error when trying to Install SharePoint Service pack”

Today I had this problem with this language packs:

  • German
  • French
  • Spain
  • Russian

Looking around the internet there was exactly the same issue described in a forum post:

http://social.technet.microsoft.com/Forums/de-DE/Sharepointde/thread/3aff60b7-bab7-48be-a890-be702e9ad85a

(german, sorry. Try this automatic translation: http://www.microsofttranslator.com/bv.aspx?from=de&to=en&a=http://social.technet.microsoft.com/Forums/de-DE/Sharepointde/thread/3aff60b7-bab7-48be-a890-be702e9ad85a)

…but no solution.

I’ve found several hints in the internet that this is caused by using the official “SharePoint Server 2010 with SP1” setup media.

 

Some times later I found this site:

http://salaudeen.blogspot.de/2012/01/expected-version-of-product-was-not.html

 

I tried to use the trick for the language pack SP1 installers:

SNAGHTML13df27f

W:SP_Setup240_SP1SPSserverlanguagepack2010sp1-kb2460056-x64-fullfile-de-de.exe PACKAGE.BYPASS.DETECTION.CHECK=1

 

This solved my issue. I was able to install the SP1 for all affected language packs. – I’m not sure this is a valid procedure for production systems.

Redirecting to new URL with IIS

In IIS there is a trick for redirecting requests to a new URL including original path and query string. This trick worked on IIS 6. Today I tried this with IIS 7.5 on Windows Server 2008 R2. It’s still working!!!

 

Demo:

1. You have an SharePoint with host header “sharepoint.local” and a Shared Documents library with a single document. This link will open the document properties view form:

http://sharepoint.local/Shared%20Documents/Forms/DispForm.aspx?ID=1&Source=http%3A%2F%2Fsharepoint%2Elocal%2FShared%2520Documents%2FForms%2FAllItems%2Easpx&RootFolder=%2FShared%20Documents&ContentTypeId=0x010100293CE4623453F044AE694E186F090B7C&IsDlg=1

2. Now you create a IIS redirect for “http://sharepoint-redirect.local”:

Therefore you create a new web application in IIS:

image

Now you add “Http Redirect” functionality to the web application:

image

image

Click “Apply” after configuration.

3. If you test it in the browser with URLs like http://sharepoint-redirect.local/Shared%20Documents it works as expected. You get http://sharepoint.local/Shared%20Documents

4. But if you try the link from above you get an unexpected result:

http://sharepoint-redirect.local/Shared%20Documents/Forms/DispForm.aspx?ID=1&Source=http%3A%2F%2Fsharepoint%2Elocal%2FShared%2520Documents%2FForms%2FAllItems%2Easpx&RootFolder=%2FShared%20Documents&ContentTypeId=0x010100293CE4623453F044AE694E186F090B7C&IsDlg=1

redirected to:

http://sharepoint.local/SitePages/Home.aspx

5. If you uncheck (and “Apply”) the following checkbox in the HTTP Redirect settings of the web application it looks a little bit better:

image

 

http://sharepoint-redirect.local/Shared%20Documents/Forms/DispForm.aspx?ID=1&Source=http%3A%2F%2Fsharepoint%2Elocal%2FShared%2520Documents%2FForms%2FAllItems%2Easpx&RootFolder=%2FShared%20Documents&ContentTypeId=0x010100293CE4623453F044AE694E186F090B7C&IsDlg=1

redirected to:

http://sharepoint.local/Shared%20Documents/Forms/DispForm.aspx

The URL is correct but the query string is missing. So the form is empty:

image

6. Now the “old” IIS trick for HTTP Redirect:

Use tokens $S$Q in the redirect URL!

$S = Path

$Q = Query String

image

Now it HTTP Redirect works as expected!

http://sharepoint-redirect.local/Shared%20Documents/Forms/DispForm.aspx?ID=1&Source=http%3A%2F%2Fsharepoint%2Elocal%2FShared%2520Documents%2FForms%2FAllItems%2Easpx&RootFolder=%2FShared%20Documents&ContentTypeId=0x010100293CE4623453F044AE694E186F090B7C&IsDlg=1

redirected to:

http://sharepoint.local/Shared%20Documents/Forms/DispForm.aspx?ID=1&Source=http%3A%2F%2Fsharepoint%2Elocal%2FShared%2520Documents%2FForms%2FAllItems%2Easpx&RootFolder=%2FShared%20Documents&ContentTypeId=0x010100293CE4623453F044AE694E186F090B7C&IsDlg=1/Shared%20Documents/Forms/DispForm.aspx

 

image

For MCTs: Classroom Setup Tools for MS Learning Hyper-V machines

(Download link below!)

If you set up a MS Learning Classroom with Hyper-V and the images provided by MS at the MCT download page you need to deploy the VHD files (and the other VM files of course) to “C:ProgrammeMicrosoft Learning<…>”

The last days I set up a new Hyper-V server at my office:

  • 128GB SSD => system
  • 2TB HDD => machines
  • 32GB RAM

I want to store the MS Learning machines on “D:” (=> 2TB).

The MS Learning machines have differential VHDs that are based on a couple of “Base VHDs”. In all differential VHD files there are references to the location of the original file:

image

Furthermore there are to files for every machine that contain config and export/import informations. This files have absolute file location references too.

Because this MS Learning machines are not productive Hyper-V machines I decided to manipulate a neseccary files to be able to store the machines on another drive. Manipulating this files is not supported!!!

My package contains 4 PowerShell scripts:

1. “Unpack”

image

This script allows you to decompress all compressed MS Learning machines in a folder to a destination folder.

To run the script you need to have “unrar.exe” in the same directory as the script. Download and execute this file ftp://ftp.rarlab.com/rar/unrarw32.exe. This is an self extracting archive that contains “unrar.exe”.

You only need to manipulate the “$list” variable: specify all source directories and destination directories you need to extract.

In my case this is the result:

image

2. “Patch”

This script manipulates all neseccary files.

You need to have them all in a dedicated directory. In my case everything is located under “I:Learning”. This directory is the entry point for the other scripts. In this directory all base and differential VHDs must be located.

“Patch” modifies:

  • config.xml => replace VHD paths
  • <machine-guid>.exp => replace VHD paths
  • <name>.vhd / <name>.avhd => replace VHD paths

First the “Patch” script scans the root path (e.g. “I:Learning”) and all sub directories. It saves all VHD file names.

The next steps are to open the files specified above and replace all VHD paths (“c:program files…”) with the correct paths (“I:Learning…”).

For “config.xml” und “<machine-guid>.exp” the script creates backup files with the same name and additional “.bak” extension. If you run the script twice the backup will be restored before processing.

For “<machine-guid>.exp” another file will be creates: “<machine-guid>.exp.ik”. This file is used later for patching the virtual machine in Hyper-V.

3. “ImportVMs”

This script imports the MS Learning Machines to Hyper-V using WMI (see http://social.technet.microsoft.com/Forums/en-US/winserverClustering/thread/a4e0d12d-534c-41f6-8038-4e8a7dbbba15).

image

It imports every machine found in the sub directories of the given machine root: “I:Learning”

4. “mountVHDs”

You maybe need to mount the VHDs after importing.

This is a part of the “Classroom Setup Guide” for one training:

image

In my case this happens for all machines!!! – In case of course no. “10174” (SharePoint Config and Admin) you would have to pathc 15 machines with about 20 VHD files. You would have to repeat mounting the VHDs on every classroom machine!!! – NO WAY!

image

While importing the machines you get this event log entries in the Hyper-V VMMS/Admin event log:

  1. Import task failed to fix up connection information for connection ‘I:Learning10174Drives10174A-SP2010-WFE1-FINALVirtual Hard Disks10174A-SP2010-WFE1-FINAL.vhd’. (Event Id 18430)
  2. Import task failed to fix up connection information for connection ‘I:Learning10174Drives10174A-SP2010-WFE1-FINALVirtual Hard Disks10174A-SP2010-WFE1-Allfiles-diff.vhd’. (Event Id 18430)
  3. ‘10174A-SP2010-WFE1-FINAL’: The file name ” is invalid. You cannot use the following names (LPTn, COMn, PRN, AUX, NUL, CON) because they are reserved by Windows. (Virtual machine ID FE26F0D1-B18C-440D-8CB6-792DBB6E1A5B) (Event Id 12634)
  4. ‘10174A-SP2010-WFE1-FINAL’ failed to add device ‘Microsoft Virtual Hard Disk’. (Virtual machine ID FE26F0D1-B18C-440D-8CB6-792DBB6E1A5B) (Event Id 14140)
  5. Failed to import correctly the device ‘{ResourceType=21, OtherResourceType="<null>", ResourceSubType="Microsoft Virtual Hard Disk"}’ for ‘10174A-SP2010-WFE1-FINAL’ (Virtual machine ID FE26F0D1-B18C-440D-8CB6-792DBB6E1A5B). Error: Invalid parameter (0x80041008) . (Event Id 18130)
  6. Import completed with warnings. Please check the Admin events in the Hyper-V-VMMS event log for more information. (Event Id 18250)

(This are examples! The paths and names will vary!)

 

image

 

The script “MountVHDs” will modify all machines in Hyper-V. ALL machines!! Be very carefull!! Again: Don’t use the scripts in a production environment!!!

To execute this script you need to install the PowerShell Hyper-V module: http://pshyperv.codeplex.com/

The script opens every machine. Than it searches in the MS Learning Root (“i:learning”) for the file “<machine-guid>.exp.ik”. If there is such a file the script modifies the virtual machine and mounts the VHDs as configured in the “EXP.IK” file.

For me it works perfectly! – Now I can set up my classroom server in few minutes!

Here you can download the scripts: http://pscst.codeplex.com – Please feel free to improve them – and to send me your improvements!!!

Create WSP (Cab) file on SharePoint Server using SharePoint Built-in functionality

SharePoint Server 2010 and Foundation too has a namespace “Microsoft.SharePoint.Utilities.Cab”. In this namespace there are all functions you need to create CAB=WSP files. – I have already used this functionality in a private project: https://blog.kenaro.com/2012/02/29/demo-generating-sandboxed-solutions-through-code-for-sharepoint-2010/

Here is the PowerShell script to create create CAB = WSP files on a SharePoint server:

# Written by Ingo Karstein (https://blog.kenaro.com)
#   v0.1.0.0 / 2012-05-01

$destWSPfilename = "C:UsersAdministratorSourceMyWSP.wsp"
$sourceSolutionDir = [System.IO.DirectoryInfo]"C:UsersAdministratorSourceMyWSP_Content"

##################################

$a = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$ctor = $a.GetType("Microsoft.SharePoint.Utilities.Cab.CabinetInfo").GetConstructors("Instance, NonPublic")[0]

$cabInf = $ctor.Invoke($destWSPfilename );

$mi = $cabInf.GetType().GetMethods("NonPublic, Instance, DeclaredOnly")
$mi2 = $null
foreach( $m in $mi ) {
    if( $m.Name -eq "CompressDirectory" -and $m.GetParameters().Length -eq 4 ) {
        $mi2 = $m;
        break;
    };
}

$mi2.Invoke($cabInf, @( $sourceSolutionDir.FullName, $true, -1,$null ));

PS2EXE v0.2.0.0: Improvements: Platform switch (x64 or x86 or AnyCPU), new “EXE.config” file for “supported runtime”

(Original article: https://blog.kenaro.com/2011/06/21/ps2exe-tool-for-converting-powershell-scripts-to-standalone-exe-files/)

I have implemented some new switches for PS2EXE:

-x86

This compiles the EXE to be run as 32 bit application also on 64 bit OS.

-x64

This compiles the EXE to be run as 64 bit application. Therefore an 64 bit OS ist necessary.

-runtime20

This creates an “.exe.config” file with this content:

<configuration>
   <startup>
      <supportedRuntime version="v2.0.50727"/>
   </startup>
</configuration>

Please read this article on MSDN http://msdn.microsoft.com/en-us/library/w4atty68.aspx

this may fix some errors that users reported to me.

 

You can download the new version ouf PS2EXE here:

http://ps2exe.codeplex.com

Error in crawl log: “The SharePoint item being crawled returned an error when attempting to download the item”

Another error in the crawl log:

SNAGHTML3dde524

Using Fiddler I figured out that the pages report an “incompatible browser” error if the SharePoint crawler opens that pages. It seems that the gantt view only renders content for an up-to-date Internet Explorer – identified by the user agent.

The solution is to change the user agent used by the SharePoint crawler component.

Microsoft’s “procmon” showed me this registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\14.0\Search\Global\Gathering Manager\UserAgent

I set this to the IE9 user agent string found here: http://blogs.msdn.com/b/ie/archive/2010/03/23/introducing-ie9-s-user-agent-string.aspx

It’s:

Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)

After the next crawl the errors related to this problem where gone.

Error in crawl log: “The server is unavailable and could not be accessed. The server is probably disconnected from the network.” (SharePoint 2010)

I got this error messages a thousand times:

image

Solution 1:

I added the root certification authority certificates and the intermediate certification authority certificates of all SSL certificates to the SharePoint root cert store:

$rootca = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("$(join-path (split-path $MyInvocation.MyCommand.Path) 'root-ca.cer')") 
$interca = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("$(join-path (split-path $MyInvocation.MyCommand.Path) 'inter-ca.cer')") 

New-SPTrustedRootAuthority –Name "GlobalSign Root CA" –Certificate $rootca 
New-SPTrustedRootAuthority –Name "GlobalSign Domain Validation CA" –Certificate $interca 

In my case both certificates are saved as CER files in the same directory as the script file above.

 

To get the root and intermediate CA cert open the Internet Explorer and navigate to the SharePoint site.

Click the “Security Report” button:

image

Click “View certificates”

image

Select every certificate in the tree but not the last level: this last certificate is your SSL certificate itself. The top certificate is the “root certification authority certificate” and all certificates (1 or more) between the top node and the “last” certificate are the “intermediate certification authority certificates”. Select each of them and click “View Certificate”.

image

In the next dialog click “Details” and then click “Copy to file”

image

Solution 2:

Maybe this is another solution for the problem.

First open the Farm Search Administration page (http(s)://<ca>:<port>/searchfarmdashboard.aspx).

Then change the setting “Ignore SSL warnings” to “yes”:

image

Demo: Generating Sandboxed Solutions Through Code for SharePoint 2010

Some weeks ago I startet a new private dev project.

To reach one of the goals of the project I thought about the possibility to create Sandboxed Solutions at runtime. I’ve extracted this aspect of the project to show you how to create Sandboxed Solutions on the fly.

 

In my demo scenario for this blog article I’d like to have a custom list that enables me to create entries in the “Edit Control Block” at runtime. For every list item that is created in the custom list a Sandboxed Solution will be created and uploaded to the solution gallery of the site collection.

 

Let’s have a look:

 

1. First we look into the solution gallery of “http://sharepoint.local”. It’s empty.

image

2. I’ve created my demo solution and deployed it. This solution contains a list template and list instance. The list instance is shown in the Quick Launch as “Dynamic Menu”.

image

3. Now I create a new entry in this list:

image

image

4. Now we look into the solution gallery:

image

There is a new Sandboxed Solution in it!!

5. In the Shared Documents libary I have a single file “My PDF”. Now I open the files context menu:

image

image

6. After creating a new item in the “Dynamic Menu” I get a new entry in the Edit Control Menu:

image

image

This opens a new Outlook Window with the item URL as body.

image

7. For every generated solution there is an entry in the Site Collection Features list:

image

image

 

How does it work?

1. First I’ve created a list template and list instance.

2. Then I’ve created a Event Receiver.

image

There are two methods:

  • Utilities.RemoveSolution
  • Utilities.AddSolution

3. Method “Utilities.AddSolution”

This static method creates the Sandboxed Solution.

Therefore internal non-public methods of SharePoint are invoked. This is the most interesting aspect of the demo project!

ConstructorInfo ctor = typeof(Microsoft.SharePoint.SPSolutionExporter).Assembly.GetType("Microsoft.SharePoint.Utilities.Cab.CabinetInfo").GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic)[0];
object cabInf = ctor.Invoke(new object[] { solutionFileName });

MethodInfo[] mi = cabInf.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
MethodInfo mi2 = null;
foreach( var m in mi )
    if( m.Name == "CompressDirectory" && m.GetParameters().Length == 4 )
    {
       mi2 = m;
       break;
    };

mi2.Invoke(cabInf, new object[] { solutionDir.FullName, true, -1, null });

 

In the source code before this snippet I create the structure of a WSP file in a temporary folder in the file system. The shown code creates the WSP file that I upload into the solution gallery.

4. Utilities.RemoveSolution

This static method removes the solution from the solution gallery.

5. You can download the complete code from codeplex:

http://spautogensolution.codeplex.com/

Minify JavaScript and PowerShell scripts by using PowerShell

There are several tools out there to minify JavaScript files. – You don’t know “minification”? Look here: http://en.wikipedia.org/wiki/Minification_(programming)

Common tools are:

For those of you that like PowerShell as I like it I’ve created a PowerShell module that let’s you minify JavaScript files and PowerShell script files.

Here it is on Codeplex: http://minifyps.codeplex.com/

2020/11/17: Now on GitHub: https://github.com/ikarstein/minifyPS

You can use the module like this:

cls

#module in the same path as the script:
Import-Module (join-path (split-path $MyInvocation.mycommand.path) "minjs")

#module in a default module path like "C:WindowsSystem32WindowsPowerShellv1.0ModulesminifyPS"
#Import-Module "minjs"

$str = @"
    var test = 'some JavascriptCode';
"@

$min = (minify -inputData $str -inputDataType "js")

[System.Windows.Forms.Clipboard]::SetText($min )

The module works like this:

1. Split script source code into typed chunks:

  • Code
  • Single Quoted String
  • Double Quoted String
  • Multiline Comment
  • End-of-line Comment

2. Remove all unwanted chunks such as comments

3. Process all remaining chunks by using regular expressions

4. Combine all processed chucks to a result string

For every language (JavaScript and PowerShell) there is a config section in the script.

image

There are two files in the package at Codeplex:

image

  • “minJS.psm1” => This is the module
  • “minJSDemo.ps1” => This is a demo script that uses the module

The demo script contains a piece of JavaScript that will be minified. And the script will minify itself and the module to an “output” sub directory that is created by the script if it does not exist.

This is a screenshot after running the demo script:

image

If you execute “minJSDemo.min.ps1” in the output folder you execute the minified version of “minJSDemo.ps1” and the minified version of the module itself (“minJSmin.psm1”).

The module is ALPHA at the moment. I’ve tested it in some projects and it seems to work as expected.

I’ve tested it with a huge JavaScript file: “core.debug.js” of Microsoft SharePoint:

C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14TEMPLATELAYOUTS<lcid>CORE.debug.js

I’ve renamed the original file to “core.debug.js.bak”, minified it and saved the result as “code.debug.js”. So it’s used in the browser. (The minification of ~360KB takes 90 seconds.The minification module is slow…)  

It’s not possible to use the minified version. It seems that the original “code.debug.js” has some bugs. For example in line 42: There is no trailing “;”

image

But because of removing the line break this results in:

image

This causes the following JavaScript error in Internet Exlorer:

image

I’d be happy to hear about your experiences with the module. Please post comment, write me an e-mail or join the Codeplex-project!