May 03 2017 05:04 AM - edited May 03 2017 05:06 AM
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
May 08 2017 06:58 PM
May 24 2017 06:35 PM
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.
May 28 2017 12:22 AM
May 29 2017 09:38 PM
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
May 29 2017 10:07 PM
May 30 2017 05:44 PM
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,
May 30 2017 10:12 PM
May 30 2017 10:36 PM
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
May 31 2017 07:59 PM
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.