Some of you may have noticed my recent posts on some questions in the forum. Here’s another one… 🙂
I’m trying to create some deployment scripts using PowerShell. I’m able to connect to my tenant but am not able to do much with it afterwards. Any thoughts?
Add-Type -Path “C:\dll\Microsoft.SharePoint.Client.dll”
Add-Type -Path “C:\dll\Microsoft.SharePoint.Client.Runtime.dll”
Add-Type -Path “C:\dll\Microsoft.SharePoint.Client.Taxonomy.dll”
$tenantAdmin = “https://tenant-admin.sharepoint.com”
$tenantRoot = “https://tenant.sharepoint.com”
$adminUser = “haniel@tenant.onmicrosoft.com”
$password = “password”
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($adminUser, $securePassword)
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($tenantRoot)
$ctx.Credentials = $credentials
$webs = $ctx.Web
$ctx.Web or other objects I’m trying to access come back as null. Any thoughts?
Hi Ryan,
I’m running on a Windows 10 preview environment without SharePoint. My goal is to do some work with CSOM and am hitting a roadblock. I’m not sure if it’s related to the fact that the Microsoft.SharePoint.PowerShell snapin is not registered.
I create the following context:
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext $url
Now when I try to use it to get the taxonomy session using
$spTS = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($spContext)
I get the following error
Cannot convert argument “context”, with value: “Microsoft.SharePoint.Client.ClientContext”, for “GetTaxonomySession” to
type “Microsoft.SharePoint.Client.ClientRuntimeContext”: “Cannot convert the “Microsoft.SharePoint.Client.ClientContext”
value of type “Microsoft.SharePoint.Client.ClientContext” to type “Microsoft.SharePoint.Client.ClientRuntimeContext”.”
I have seen many people online do the same thing and it works for them so I have no idea why it’s not working for me. Trying to get other information such as web or site information from the context works fine.
Could it be because the Microsoft.SharePoint.PowerShell snapin isn’t loading? I have the SharePoint Online Management Shell installed but when I run the Get-PsSnapin -name Microsoft.SharePoint.Powershell it returns an error and Get-Module shows Microsoft.Online.SharePoint.Powershell.
Thanks for your help,
-Haniel