Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8411339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:24:08+00:00 2026-06-10T00:24:08+00:00

I have an ASP.NET MVC 3 application which uses PowerShell to connect to Office

  • 0

I have an ASP.NET MVC 3 application which uses PowerShell to connect to Office 365 to retrieve some details about user licenses.

The code itself works in many cases:

  • The project in my local IIS works
  • A piece of code in LINQPad using the library works on my machine
  • A piece of code in LINQPad using the library works on the target server

And where it doesn’t work is of course the only place it really should work: The IIS on the target server.

I always get an Exception when calling the Connect-MsolService cmdlet. The problem is that the Exception doesn’t tell me anything.

The Exception type is

Microsoft.Online.Administration.Automation.MicrosoftOnlineException

and the message is

Exception of type ‘Microsoft.Online.Administration.Automation.MicrosoftOnlineException’ was thrown

which is pretty useless.

The Office 365 user account I use in my code is always the same. The user account used to start the IIS is always the same, too (Local System).

I wrapped the PowerShell code execution in a class named PowerShellInvoker. Its code can be found here.

And here is the code that connects to Office 365:

var cred = new PSCredential(upn, password);

_psi = new PowerShellInvoker("MSOnline");
_psi.ExecuteCommand("Connect-MsolService", new { Credential = cred });

There is no Exception actually thrown, the error is found in the Error property of the pipeline. (See lines 50ff. of the PowerShellInvoker class.)

The problem is that I don’t know what could be wrong, especially because the same code works when I use LINQPad. The search results by Google couldn’t help me either.

The server runs on Windows Server 2008 R2 Datacenter SP1 with IIS 7.5.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T00:24:09+00:00Added an answer on June 10, 2026 at 12:24 am

    I found the solution!

    I don’t know the reason, but on the target server, the app pool’s advanced settings for my app had set Load User Profile to False. I changed it back to True (which should be default) and voilà, it works!

    Edit: The Load User Profile setting was apparently automatically set to False by default because the IIS 6.0 Manager was installed and False was the default behavior until IIS 6.0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an ASP.NET application on ASP.NET 4.0 using MVC 3 which uses Windows
I have an asp.net mvc application, which uses the default user database. It all
I have an MVC 3 application which uses asp.net authentication. I have just created
I have an ASP.NET MVC application which uses Entity Framework to get data. I
I have an ASP.NET MVC 4 application which uses the new ASP.NET Web API.
I have an ASP.NET MVC application which uses plain HTML. I quickly need to
I have an Asp.net MVC application which uses html5 and jquery on the client
I have a ASP.NET MVC application which is build up as an assembly that
I have an ASP.NET MVC 3 application which has a post action called Create
I have an .NET 4.0 ASP.NET MVC application, which also hosts a Workflow Foundation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.