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?
Not sure if this will help anyone but I had this issue for weeks until Paul C. on here helped me realize that I was using the SharePoint Online Management Shell instead of the generic PowerShell ISE or PowerShell window. I am just not using the SharePoint Online Management Shell for my scripts, I am just using my basic PowerShell console on my local machine instead.
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
I would be inclined to suggest that Haniel is trying to run your script on his own machine and not on a SharePoint Server – which your script would require as it is using the Snapin Module for SharePoint Server
Seems like the error is communicating that Windows Powershell version 5 (is it out of preview yet?) may not be registered properly on the environment where you are running the script from… that’s what I would check first, or maybe back down to a different version of powershell possibly if version 5 is still in a preview state. Sorry I don’t have anything concrete on this issue for you to go to or try out.
Dave
Feel free to email me any screen shots that you can take of the issues as ive tested it on PS v2 and above – I’m currently running Win10 and it works fine for me
ryan.yates@kilsauit.org