When creating the sharepoint site using ps1 file from C# code in office365. This error is coming The 'connect-sposervice' command was found in the module 'Microsoft.Online.SharePoint.PowerShell', but the module could not be loaded. For more information, run 'Import-Module Microsoft.Online.SharePoint.PowerShell'.
Running the ps1 directly in powershell is giving the desired result, but not working properly using c# code
I had the same problem and solve it this way:
Locate file
C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.Online.SharePoint.PowerShell.psd1
and change this line
for this one:
I don't know if it's a good solution, but it's works for me. Any suggestion is wellcome