none
The partner returned a bad sign-in name or password error. For more information, see Federation Error-handling Scenarios RRS feed

  • Question

  • I'm trying to use PowerShell to perform actions in Project Online. On my computer, it works. In Azure Automation, it doesn't work. It's the same exact code copy / pasted. In Azure I get the error:

    Exception calling "ExecuteQuery" with "0" argument(s): "The partner returned a bad sign-in name or password error. For 
    more information, see Federation Error-handling Scenarios."

    I had this error on my PC until I added code to change the request headers based on some research I did. Now my computer can run this perfectly, but it still gets the error in Azure. I also tried Azure hybrid runbook workers, but those get the error also. No clue why this is happening. Here's the code that works on my PC but fails in Azure:

    $Assemblies = (
        "$($PSScriptRoot)\Microsoft.ProjectServer.Client.dll",
        "$($PSScriptRoot)\Microsoft.SharePoint.Client.dll",
        "$($PSScriptRoot)\Microsoft.SharePoint.Client.Runtime.dll",
        'System.Data.Linq',
        'System.Runtime',
        'System.Linq.Expressions',
        'System.Threading.Tasks'
    )
    
    $Source = @'
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Data;
    using System.Text;
    using System.Threading.Tasks;
    using System.Net;
    using System.Runtime;
    
    using Microsoft.SharePoint.Client;
    using csom = Microsoft.ProjectServer.Client;
    
    namespace CNCYProject
    {
        public static class ClientContextHelper
        {
            public static void AddRequestHandler(ClientContext context)
            {
                context.ExecutingWebRequest += new EventHandler<WebRequestEventArgs>(RequestHandler);
            }
    
            private static void RequestHandler(object sender, WebRequestEventArgs e)
            {
                //Add the header that tells SharePoint to use Windows authentication.
                e.WebRequestExecutor.RequestHeaders.Remove("X-FORMS_BASED_AUTH_ACCEPTED");
                e.WebRequestExecutor.RequestHeaders.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
            }
        }
    }
    '@
    Add-Type -ReferencedAssemblies $Assemblies -TypeDefinition $Source -Language CSharp
    $siteUrl = ''
    $username = ''
    $password = ConvertTo-SecureString -String '' -AsPlainText -Force
    
    $ProjectContext = [Microsoft.ProjectServer.Client.ProjectContext]::new($siteUrl)
    $ProjectContext.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $Password)
    [CNCYProject.ClientContextHelper]::AddRequestHandler($ProjectContext)
    
    $ProjectContext.Load($ProjectContext.Projects)
    $ProjectContext.ExecuteQuery()


    How do I get this to work in Azure? I am using a federated login. I can switch to an onmicrosoft account, but will not set up a service account as global Office 365 admin, so I don't think onmicrosoft is an option. It's weird that this code executes perfectly on my computer but fails in the cloud...

    Saturday, December 10, 2016 12:58 AM

All replies

  • Hello Ryan,

    I have the same issue. Can you please let me know what you did to fix this issue?

    Thank you.

    Monday, February 25, 2019 8:47 PM