How to execute PowerShell scripts from C# with an execution policy unrestricted

When you are running a PowerShell script, you might get the error:

System.Management.Automation.PSSecurityException : File Test.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.



In development set the execution policy to Unrestricted.

Set-ExecutionPolicy Unrestricted


PowerShell script (runs a function from an custom assembly)

    [String]$Connection = "",     #The database connectionstring
    [String]$Folder = ""            #The AppPool UserName
$dd = new-object Ada.Cdf.Deployment.DatabaseDeployment
$dd.ExecuteReCreatableScriptsInFolder($Connection, $Folder)



        [Explicit("Not a unittest")]
        public void RunExecuteReCreatableScriptsInFolder()
            List<string> parameters = new List<string>(){@"Data Source=.;Initial Catalog=TestDB;Integrated Security=SSPI;", @"C:\Temp"};
            // Run a PowerShell script with two parameter and set execution policy to Unrestricted
            RunPowershellScript(@"C:\Temp\Test.ps1", parameters);
        private static void RunPowershellScript(string scriptFile, List<string> parameters)
            // Validate parameters
            if (string.IsNullOrEmpty(scriptFile)) { throw new ArgumentNullException("scriptFile"); }
            if (parameters == null) { throw new ArgumentNullException("parameters"); }

            RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();
            using (Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration))
                RunspaceInvoke scriptInvoker = new RunspaceInvoke(runspace);
                scriptInvoker.Invoke("Set-ExecutionPolicy Unrestricted");
                Pipeline pipeline = runspace.CreatePipeline();
                Command scriptCommand = new Command(scriptFile);
                Collection<CommandParameter> commandParameters = new Collection<CommandParameter>();
                foreach (string scriptParameter in parameters)
                    CommandParameter commandParm = new CommandParameter(null, scriptParameter);
                Collection<PSObject> psObjects;
                psObjects = pipeline.Invoke();



How to show more appointments in the To-Do Bar of Microsoft Outlook 2010

If you wanted to view more appointments in the To-Do Bar of Microsoft Outlook 2007, you could change the default of 3 by right clicking on the To-Do Bar > Views > To-Do Bar > Options > Show Appointments > Number of appointments.





This option is removed in Microsoft Outlook 2010:



To show more appointments in the To-Do Bar just increase the viewed space by dragging the divider bar:


In cooperation with Marc Valk

Styling, branding SharePoint 2010 based on Active Directory users and groups, no code required, only CSS and Document Permissions

To style a SharePoint 2010 site, based on the current user and his active directory role, I use document permissions on css files in the Style Library.

The goal of the blog post is to Show a a logo of a man, when the current user is member of the Active Directory role [Men] and show a logo of a Woman, when the current user is member of the Active Directory role [Women].


Woman (Elise) signs in



Men (Bas) signs in




  • In Active Directory create two roles: [Men] and Women
  • In Active Directory create the users [Bas] and make him member of the role [Men]
  • In Active Directory create the users [Elise] and make her member of the role [Women]
  • In SharePoint 2010 go to Site Actions > Site Permission on you’re site collection top level site
  • Grant Permissions [Full Control] to the Active Directory groups: [Men] and [Women]


  • Create two css files on you’re desktop: Men.css and Women.css
  • Men.css contains:

    background-repeat: no-repeat;
    background-position: top left;
    height: 425px;

  • Women.css cotains:

    background-repeat: no-repeat;
    background-position: top left;
    height: 425px;


  • Go to you’re SharePoint top level site, click on Site Actions > Site Settings


  • Site Administration > Content and structure


  • Upload Women.png and Men.png to the Style Library\Images by dragging and dropping the files (New > Item > Upload Multiple Files…)
  • Create Images folder if it does not exist in the [Style Library]



  • After upload check the files in


  • Upload Men.css and Women.css to the Style Library and check in files
  • Manage permissions on Men.css to include only men (click on Manage Permissions > Stop inherriting permissions), remove user permissions for women
  • Manage permissions on Women.css to include only women(click on Manage Permissions > Stop inherriting permissions), remove user permissions for men


  • Open Microsoft SharePoint Designer and open you’re site then click on Master Pages > v4.master
  • Click on Attach Style Sheet, browse for the Men.css stylesheet and click on Import > OK
  • Repeat for Women.css
  • The only thing what this does, is adding the following lines at the end of the <head> tag in the master page

@import url(‘../../Style%20Library/Men.css’);
@import url(‘../../Style%20Library/Women.css’);


  • Make sure all persons have read rights on the Master Page Gallery and the v4.master is checked in after you edit the file to import Men.css and Women.css


  • On you’re team site, click in the ribbon on Page > Edit


  • Click in the ribbon on Format Text > HTML > Edit HTML Source
  • Add <div class=”logo”></div> to the content editor webpart


  • Click on OK then in the ribbon on Save


Result, see beginning of this blog post

How to resolve: ListBox UI does not update (refresh) on WCF .NET Ria Services domaincontext async call in Silverlight 3

When you are calling a function on a WCF .NET RIA service, the completed eventhandler will take you back to the UI thread, but if you are binding the ListBox to a List<….> the UI of the Listbox won’t be updated.

Solution: don’t use a List<…> as ItemSource but a System.Collections.ObjectModel.ObservableCollection<…>

Errors after installing Microsoft Office Web Apps

After installing Microsoft Office Web Apps on a SharePoint 2010 server, I got an error when displaying a word (*.docx) file:


An unexpected error has occurred.

Troubleshoot issues with Microsoft SharePoint Foundation.

Correlation ID: 848a2b82-a1a4-4faf-895e-1451464fa3b0

Date and Time: 3/10/2010 8:18:03 AM




After activating the Microsoft Office Web Apps feature on the site collection:



this error was resolved and Microsoft Office Word online started to show, but with a new error:

Word Web App cannot open this document for viewing due to an unexpected error.  To view this document, open it in Microsoft Word.
Error Id: 557be21f-f14d-4c76-9be5-d07f2a04b8f9, 20100310083103


This was because you need some additional steps when installing Microsoft Office Web App on a DC, see:


But the error was not resolved:

Word Web App cannot open this document for viewing due to an unexpected error.  To view this document, open it in Microsoft Word.
Error Id: 3b5ec400-4f95-495b-b663-320b9b9692be, 20100310124900



Followed the steps on:

Followed the steps on:

Followed the steps on:;_Practical_Tips.aspx


But the error still was not resolved, I am know rebuilding my server and starting from scratch, following the guide:

HTTP Error 500.19 – Internal Server Error after installing Microsoft Office Web Apps on a SharePoint 2010 Server

After installing Microsoft Office Web Apps (following the steps on on a Microsoft SharePoint 2010 server, I got a HTTP Error 500.19 when accessing the SharePiont Sites.



Config section ‘system.webServer/staticContent’ already defined. Sections must only appear once per config file. See the help topic <location> for exceptions

490:     </staticContent>
491:     <staticContent />
492:   </system.webServer




After removing the double <staticContent /> the site started working again.

How to sett the RootVisual multiple times from code in Silverlight 3

MSDN explains the RootVisual can only be set one time from code:

You can set the value of the RootVisual property only one time from code, although you get its value any number of times.

But we can set it to a UserControl that can switch it’s own content, as explained in the blog post:


I used this procedure to start with a progressIndicator and after authenticating the user and loading the user properties, showing the masterpage.

Get the DomainService (LINQ to SQL) to load child entities with .NET RIA Services in Silverlight 3

If you have a table with related tables then you can get the child entries by editing the DomainService and the metadata:
Add the include attribute ([Include()]) to the property containing the child table reference and use the DataLoadOptions to specify the child tables to include in the query result view.

In this case a Task table contains a reference to a Project table and the Project table contains a reference to the Customer table:


The domainservice class TTSDomainService

// TODO: Consider
// 1. Adding parameters to this method and constraining returned results, and/or
// 2. Adding query methods taking different parameters.
public IQueryable<Task> GetTasks()
    // Define the child entries to get 
    DataLoadOptions options = new DataLoadOptions();
    options.LoadWith<Task>(t => t.Project);
    options.LoadWith<Project>(p => p.Customer);
    this.DataContext.LoadOptions = options;

    // Get the tasks ordered by customer, project, task
    return from t in this.DataContext.Tasks
                 orderby t.Project.Customer.Name, t.Project.Name, t.Name
           select t;


The domainservice meta data class: TTSDomainService.metadata.cs


// The MetadataTypeAttribute identifies TaskMetadata as the class
// that carries additional metadata for the Task class.
public partial class Task

    // This class allows you to attach custom attributes to properties
    // of the Task class.
    // For example, the following marks the Xyz property as a
    // required field and specifies the format for valid values:
    //    [Required]
    //    [RegularExpression("[A-Z][A-Za-z0-9]*")]
    //    [StringLength(32)]
    //    public string Xyz;
    internal sealed class TaskMetadata

        // Metadata classes are not meant to be instantiated.
        private TaskMetadata()

        public Nullable<int> CategoryAbbrID;

        public int CategoryID;

        public Nullable<decimal> EstDuration;

        public Nullable<int> HourType;

        public string Name;

        public Project Project;

        public int ProjectID;

        public EntitySet<TaskTimeSpan> TaskTimeSpans;