I am getting an error when running the PowerShell script. Error is related to a missing assembly. Script will get the data from the SQL server and query through each item in the SharePoint list and update the values if any changes.
I tried adding libraries in the PowerShell code but I am getting the same error.
GAC Version Location
--- ------- --------
True v4.0.30319 C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.SharePoint.Client\v4.0_16.0.0.0__71e9bce111e9429c...
True v4.0.30319 C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.SharePoint.Client.Runtime\v4.0_16.0.0.0__71e9bce1...
Enter password: ************
5
Data Import Starts...
New-Object: Cannot find type [Microsoft.SharePoint.SPQuery]: verify that the assembly containing this type is loaded. At C:\SQL Server\SQLSharepointLoad.ps1:55 char:16 + $SPQuery = New-Object Microsoft.SharePoint.SPQuery + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo: InvalidType: (:) [New-Object], PSArgumentException + FullyQualifiedErrorId: TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
The property 'Query' cannot be found on this object. Verify that the property exists and can be set. At C:\SQL Server\SQLSharepointLoad.ps1:56 char:5 + $SPQuery.Query = "
If you want to get data from SQL Server, you could use SQL Server PowerShell, check below thread.
Using Powershell get Values from sql table
If you want to get data from SharePoint, I do suggest you use CSOM to query SharePoint list data(SPQuery is SSOM which can be run in SharePoint server).
You could get CSOM SDK from
2013
https://www.microsoft.com/en-us/download/details.aspx?id=35585
2016
https://www.microsoft.com/en-us/download/details.aspx?id=51679
Sample PowerShell to connect SharePoint by PowerShell with CSOM.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.