Sharepoint online management module reference broken in azure

%3CLINGO-SUB%20id%3D%22lingo-sub-66723%22%20slang%3D%22en-US%22%3ESharepoint%20online%20management%20module%20reference%20broken%20in%20azure%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-66723%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%20azure%20web%20job%20in%20C%23%20where%20i%20am%20trying%20to%20connect%20to%20SPO%20through%20connect-sposervice.%20I%20have%20copied%20the%20complete%20Sharepoint%20online%20management%20shell%20folder%20from%20my%20local%20into%20my%20project%20and%20uploaded%20but%20still%20i%20get%20the%20error%20in%20web%20job%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3ED%3A%5Chome%5Csite%5Cwwwroot%5Capp_data%5Cjobs%5Ctriggered%5Csiteproj%0A%0A%0AUnhandled%20Exception%3A%20System.Management.Automation.CmdletInvocationException%3A%20The%20type%20initializer%20for%20'Microsoft.Online.SharePoint.PowerShell.Resources.StringResourceManager'%20threw%20an%20exception.%20---%26gt%3B%20System.TypeInitializationException%3A%20The%20type%20initializer%20for%20'Microsoft.Online.SharePoint.PowerShell.Resources.StringResourceManager'%20threw%20an%20exception.%20---%26gt%3B%20System.IO.FileNotFoundException%3A%20Could%20not%20load%20file%20or%20assembly%20'Microsoft.Online.SharePoint.PowerShell.ResourceManager.Intl%2C%20Version%3D16.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3D71e9bce111e9429c'%20or%20one%20of%20its%20dependencies.%20The%20system%20cannot%20find%20the%20file%20specified.%0A%0A%20%20%20at%20System.Reflection.RuntimeAssembly._nLoad(AssemblyName%20fileName%2C%20String%20codeBase%2C%20Evidence%20assemblySecurity%2C%20RuntimeAssembly%20locationHint%2C%20StackCrawlMark%26amp%3B%20stackMark%2C%20IntPtr%20pPrivHostBinder%2C%20Boolean%20throwOnFileNotFound%2C%20Boolean%20forIntrospection%2C%20Boolean%20suppressSecurityChecks)%0A%0A%20%20%20at%20System.Reflection.RuntimeAssembly.nLoad(AssemblyName%20fileName%2C%20String%20codeBase%2C%20Evidence%20assemblySecurity%2C%20RuntimeAssembly%20locationHint%2C%20StackCrawlMark%26amp%3B%20stackMark%2C%20IntPtr%20pPrivHostBinder%2C%20Boolean%20throwOnFileNotFound%2C%20Boolean%20forIntrospection%2C%20Boolean%20suppressSecurityChecks)%0A%0A%20%20%20at%20System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName%20assemblyRef%2C%20Evidence%20assemblySecurity%2C%20RuntimeAssembly%20reqAssembly%2C%20StackCrawlMark%26amp%3B%20stackMark%2C%20IntPtr%20pPrivHostBinder%2C%20Boolean%20throwOnFileNotFound%2C%20Boolean%20forIntrospection%2C%20Boolean%20suppressSecurityChecks)%0A%0A%20%20%20at%20System.Reflection.Assembly.Load(AssemblyName%20assemblyRef)%0A%0A%20%20%20at%20Microsoft.Online.SharePoint.PowerShell.Resources.StringResourceManager..cctor()%0A%0A%20%20%20---%20End%20of%20inner%20exception%20stack%20trace%20---%0A%0A%20%20%20at%20Microsoft.Online.SharePoint.PowerShell.Resources.StringResourceManager.GetResourceString(String%20resourceId%2C%20Object%5B%5D%20args)%0A%0A%20%20%20at%20Microsoft.Online.SharePoint.PowerShell.GetSite.ProcessRecord()%0A%0A%20%20%20at%20System.Management.Automation.Cmdlet.DoProcessRecord()%0A%0A%20%20%20at%20System.Management.Automation.CommandProcessor.ProcessRecord()%0A%0A%20%20%20---%20End%20of%20inner%20exception%20stack%20trace%20---%0A%0A%20%20%20at%20System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable%20input)%0A%0A%0A%3C%2FPRE%3E%3CP%3Ecan%20anyone%20help%20or%20tell%20a%20better%20way%20to%20run%20powershell%20to%20SPOnline%20commandlets%20from%20Azure%20web%20job.%20Or%20is%20it%20Powershell%20is%20not%20for%20Azure%20%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-66723%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESPO%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-74285%22%20slang%3D%22en-US%22%3ERe%3A%20Sharepoint%20online%20management%20module%20reference%20broken%20in%20azure%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-74285%22%20slang%3D%22en-US%22%3E%3CP%3EI%20was%20trying%20to%20call%20the%20powershell%20code%20initially%20from%20c%23%20but%20when%20the%20web%20job%20was%20being%20hosted%20in%20azure%20then%20the%20powershell%20objects%20were%20throwing%20exception%20as%20it%20was%20not%20able%20to%20find%20reference%20to%20Sharepoint%20Online%20powershell%20dll's%20module.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-73977%22%20slang%3D%22en-US%22%3ERe%3A%20Sharepoint%20online%20management%20module%20reference%20broken%20in%20azure%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-73977%22%20slang%3D%22en-US%22%3E%3CP%3EIn%20addition%20to%20porting%20the%20code%20into%20c%23%20you%20can%20call%20powershell%20from%20the%20c%23%20application%20using%26nbsp%3B%3CSPAN%3Esystem.management.automation%20class.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fsystem.management.automation.powershell(v%3Dvs.85).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fsystem.management.automation.powershell(v%3Dvs.85).aspx%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-73970%22%20slang%3D%22en-US%22%3ERe%3A%20Sharepoint%20online%20management%20module%20reference%20broken%20in%20azure%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-73970%22%20slang%3D%22en-US%22%3EThe%20code%20I%20have%20shared%20with%20you%20is%20PowerShell%20code%20but%20it's%20using%20CSOM%20so%20you%20can%20easily%20port%20to%20.NET%20code%20that%20does%20essentially%20the%20same...a%20small%20correction%3A%20this%20code%20allows%20to%20get%20the%20list%20of%20all%20site%20collections%20in%20a%20SharePoint%20Online%20tenant%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-73951%22%20slang%3D%22en-US%22%3ERe%3A%20Sharepoint%20online%20management%20module%20reference%20broken%20in%20azure%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-73951%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20the%20sample%2C%20May%20be%20i%20did%20not%20put%20my%20question%20correctly%20here%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20i%20was%20initially%20trying%20was%20to%20get%20the%20list%20of%20all%20the%20site%20collection%20from%20csom%20in%20C%23%20web%20job%2C%20So%20was%20not%20able%20to%20find%20the%20tenant%20object%20in%20C%23%20to%20resolve%20that%20what%20i%20did%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMy%20intial%20approch%26nbsp%3B%3C%2FP%3E%3CP%3Efrom%20c%23%20web%20job%20call%20powershell%20object%20and%20get%20the%20site%20collection%20list%20using%20%22%26nbsp%3BGet-SPOSite%20%22%20but%20as%20i%20deployed%20the%20job%20in%20azure%20it%20was%20not%20able%20to%20find%20reference%20for%20%22Microsoft.Online.SharePoint.PowerShell%22%20and%20it%20threw%20exception.%3C%2FP%3E%3CP%3ERoadblock%26nbsp%3B%3C%2FP%3E%3CP%3EWas%20not%20able%20to%20get%20tenant%20object%20in%20C%23%20initially%20and%20later%20on%20tried%20getting%20powershell%20but%20the%20reference%20was%20not%20resolved%20%3CSPAN%3E%22%3C%2FSPAN%3E%3CSPAN%3EMicrosoft.Online.SharePoint.PowerShell%22%20%26nbsp%3B%3C%2FSPAN%3Ein%20azure%20web%20job%20code.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFinal%20approch%26nbsp%3B%3C%2FP%3E%3CP%3EI%20moved%20the%20compelte%20code%20in%20powershell%20to%20get%20site%20collection%20list%20and%20write%20back%20to%20sharepoint%20list%20and%20deployed%20as%20runbook.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EKindly%20correct%20me%20if%20i%20am%20wrong%20but%20is%20there%20a%20way%20in%20c%23%20to%20get%20list%20of%20all%20site%20collections%20in%20a%20farm.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-73708%22%20slang%3D%22en-US%22%3ERe%3A%20Sharepoint%20online%20management%20module%20reference%20broken%20in%20azure%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-73708%22%20slang%3D%22en-US%22%3EHere%20you%20are%20%3A)%3C%2Fimg%3E%20%3CA%20href%3D%22https%3A%2F%2Fgallery.technet.microsoft.com%2FHow-to-get-all-the-tenant-2999c21b%3Fredir%3D0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgallery.technet.microsoft.com%2FHow-to-get-all-the-tenant-2999c21b%3Fredir%3D0%3C%2FA%3E%20as%20you%20can%20see%2C%20you%20just%20need%20to%20use%20CSOM%20dlls%20and%20no%20third%20party%20ones%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-73706%22%20slang%3D%22en-US%22%3ERe%3A%20Sharepoint%20online%20management%20module%20reference%20broken%20in%20azure%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-73706%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3BJuan%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20i%20was%20trying%20to%20do%20was%20get%20the%20site%20collections%20list%20in%20the%20tenant%20and%20details%2C%20I%20did%20not%20get%20any%20object%20in%20C%23%20to%20access%20the%20tenant%20object%20%2C%20I%20could%20see%20there%20is%20a%20third%20party%20dll%20in%20nuget%20which%20i%20could%20use%20to%20get%20the%20tenant%20object%20but%20i%20wanted%20to%20stick%20to%20microsoft.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20can%20share%20some%20example%20or%20some%20article%20that%20would%20be%20good%20to%20know%20for%20future%20knowoledge.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%2C%3C%2FP%3E%3CP%3EKJ%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-73504%22%20slang%3D%22en-US%22%3ERe%3A%20Sharepoint%20online%20management%20module%20reference%20broken%20in%20azure%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-73504%22%20slang%3D%22en-US%22%3EThat's%20not%20correct...SPO%20cmdlets%20are%20built%20on%20top%20of%20CSOM%20and%20in%20CSOM%20you%20have%20a%20tenant%20assembly%20you%20can%20use%20to%20work%20at%20the%20tenant%20level...and%20just%20as%20a%20reminder%2C%20in%20SPO%20the%20highest%20level%20you%20can%20work%20is%20the%20tenant%20level%2C%20no%20the%20farm%20one%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-72866%22%20slang%3D%22en-US%22%3ERe%3A%20Sharepoint%20online%20management%20module%20reference%20broken%20in%20azure%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-72866%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%20Peter%20for%20the%20reply.%20I%20can%20not%20use%20csom%20as%20i%20need%20to%20get%20information%20from%20the%20tenant%20and%20csom%20does%20not%20supports%20the%20tenant%20or%20farm%20object%20informtion.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20used%20azure%20automation%20to%20host%20the%20script%20and%20moved%20my%20c%23%20to%20powershell%20only.%20It%20helped%20to%20sort%20it%20out.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-68169%22%20slang%3D%22en-US%22%3ERe%3A%20Sharepoint%20online%20management%20module%20reference%20broken%20in%20azure%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-68169%22%20slang%3D%22en-US%22%3EIt%20can%20be%20tricky%20to%20use%20the%20SPOnline%20module%20from%20a%20webjob%20as%20it%20has%20a%20lot%20of%20associated%20binaries%2C%20one%20option%20could%20be%20to%20trigger%20an%20associated%20Azure%20Automation%20script%20using%20a%20webhook%20to%20then%20run%20the%20PowerShell%20components%2C%20see%20here%3A%20%3CA%20href%3D%22https%3A%2F%2Fblogs.msdn.microsoft.com%2Frazi%2F2014%2F08%2F22%2Fgetting-started-with-sharepoint-online-automation-using-azure-runbook%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fblogs.msdn.microsoft.com%2Frazi%2F2014%2F08%2F22%2Fgetting-started-with-sharepoint-online-automation-using-azure-runbook%2F%3C%2FA%3E%3CBR%20%2F%3E%3CBR%20%2F%3EAn%20alternative%20would%20be%20to%20use%20the%20CSOM%20APIs%20instead%20of%20using%20PowerShell%20at%20all%2C%20see%20here%3A%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fzimmergren.net%2Fgetting-started-with-building-azure-webjobs-timer-jobs-for-your-office-365-sites%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fzimmergren.net%2Fgetting-started-with-building-azure-webjobs-timer-jobs-for-your-office-365-sites%2F%3C%2FA%3E%3CBR%20%2F%3E%3CBR%20%2F%3EHope%20this%20helps.%3C%2FLINGO-BODY%3E
Highlighted
Contributor

I have a azure web job in C# where i am trying to connect to SPO through connect-sposervice. I have copied the complete Sharepoint online management shell folder from my local into my project and uploaded but still i get the error in web job 

 

D:\home\site\wwwroot\app_data\jobs\triggered\siteproj


Unhandled Exception: System.Management.Automation.CmdletInvocationException: The type initializer for 'Microsoft.Online.SharePoint.PowerShell.Resources.StringResourceManager' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Microsoft.Online.SharePoint.PowerShell.Resources.StringResourceManager' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Online.SharePoint.PowerShell.ResourceManager.Intl, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified.

   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)

   at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)

   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)

   at System.Reflection.Assembly.Load(AssemblyName assemblyRef)

   at Microsoft.Online.SharePoint.PowerShell.Resources.StringResourceManager..cctor()

   --- End of inner exception stack trace ---

   at Microsoft.Online.SharePoint.PowerShell.Resources.StringResourceManager.GetResourceString(String resourceId, Object[] args)

   at Microsoft.Online.SharePoint.PowerShell.GetSite.ProcessRecord()

   at System.Management.Automation.Cmdlet.DoProcessRecord()

   at System.Management.Automation.CommandProcessor.ProcessRecord()

   --- End of inner exception stack trace ---

   at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)


can anyone help or tell a better way to run powershell to SPOnline commandlets from Azure web job. Or is it Powershell is not for Azure ?

 

Thanks

9 Replies
Highlighted
It can be tricky to use the SPOnline module from a webjob as it has a lot of associated binaries, one option could be to trigger an associated Azure Automation script using a webhook to then run the PowerShell components, see here: https://blogs.msdn.microsoft.com/razi/2014/08/22/getting-started-with-sharepoint-online-automation-u...

An alternative would be to use the CSOM APIs instead of using PowerShell at all, see here:
https://zimmergren.net/getting-started-with-building-azure-webjobs-timer-jobs-for-your-office-365-si...

Hope this helps.
Highlighted

Thanks Peter for the reply. I can not use csom as i need to get information from the tenant and csom does not supports the tenant or farm object informtion. 

 

I have used azure automation to host the script and moved my c# to powershell only. It helped to sort it out.

Highlighted
That's not correct...SPO cmdlets are built on top of CSOM and in CSOM you have a tenant assembly you can use to work at the tenant level...and just as a reminder, in SPO the highest level you can work is the tenant level, no the farm one
Highlighted

Hi Juan,

 

What i was trying to do was get the site collections list in the tenant and details, I did not get any object in C# to access the tenant object , I could see there is a third party dll in nuget which i could use to get the tenant object but i wanted to stick to microsoft.

 

If you can share some example or some article that would be good to know for future knowoledge.

 

 

Thanks,

KJ

Highlighted
Here you are :) https://gallery.technet.microsoft.com/How-to-get-all-the-tenant-2999c21b?redir=0 as you can see, you just need to use CSOM dlls and no third party ones
Highlighted

Hi,

 

Thanks for the sample, May be i did not put my question correctly here 

 

What i was initially trying was to get the list of all the site collection from csom in C# web job, So was not able to find the tenant object in C# to resolve that what i did 

 

My intial approch 

from c# web job call powershell object and get the site collection list using " Get-SPOSite " but as i deployed the job in azure it was not able to find reference for "Microsoft.Online.SharePoint.PowerShell" and it threw exception.

Roadblock 

Was not able to get tenant object in C# initially and later on tried getting powershell but the reference was not resolved "Microsoft.Online.SharePoint.PowerShell"  in azure web job code.

 

Final approch 

I moved the compelte code in powershell to get site collection list and write back to sharepoint list and deployed as runbook.

 

Kindly correct me if i am wrong but is there a way in c# to get list of all site collections in a farm.

 

Thanks,

 

 

Highlighted
The code I have shared with you is PowerShell code but it's using CSOM so you can easily port to .NET code that does essentially the same...a small correction: this code allows to get the list of all site collections in a SharePoint Online tenant
Highlighted

In addition to porting the code into c# you can call powershell from the c# application using system.management.automation class.

 

https://msdn.microsoft.com/en-us/library/system.management.automation.powershell(v=vs.85).aspx

Highlighted

I was trying to call the powershell code initially from c# but when the web job was being hosted in azure then the powershell objects were throwing exception as it was not able to find reference to Sharepoint Online powershell dll's module.