1

I need to create Microsoft.Online.SharePoint.TenantManagement.Office365Tenant object.

My PowerShell Script below runs fine on my LOCAL machine, using the specified assemblies:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
Add-type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.Online.SharePoint.Client.Tenant.dll"


# Get instances to the Office 365 tenant using CSOM
$uri = New-Object System.Uri -ArgumentList $adminUrl
$context = New-Object Microsoft.SharePoint.Client.ClientContext($uri)
$context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName, $pwd)
$o365 = New-Object Microsoft.Online.SharePoint.TenantManagement.Office365Tenant($context)
$context.Load($o365)

The issue I have is getting this to work in an Azure Automation PowerShell Runbook. I have loaded the assemblies and no longer get a missing assembly error, so I think I've ruled that out. But this line in the Azure Runbook:

$o365 = New-Object Microsoft.Online.SharePoint.TenantManagement.Office365Tenant($Context)

With the error:

    New-Object : Cannot find an overload for "Office365Tenant" and the argument count: "1".

At line:32 char:9

+ $o365 = New-Object Microsoft.Online.SharePoint.TenantManagement.Offic ...

+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodException

    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

I can't figure out where else to look. The Context exists, Credentials are correct.

  • Double check you have the same version for the assemblies. That error is happening because there's not a constructor for Office365Tenant that takes a single parameter. – wjervis Jun 2 '17 at 16:28
  • That makes sense. I'll look into that. Although I zipped and imported the same assembly path into my Azure Automation Modules. – Jimmy Jun 2 '17 at 16:54
  • Looking at MSDN, there's only two signatures, and one of them expects a single parameter, so not sure why this would be throwing this exception. – wjervis Jun 2 '17 at 17:21
0

So the solution was removing the Assembly References at the top of my script.

I guess Azure Runbook will grab these assemblies for me automatically.

One of those "Are you kidding me?" moments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.