Forum Discussion
KJS
May 03, 2017Brass Contributor
Sharepoint online management module reference broken in azure
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
- Peter McDonaldIron ContributorIt 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-using-azure-runbook/
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-sites/
Hope this helps.- KJSBrass Contributor
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.
- 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