Can anyone show me how can I get the lookup field value?
I used this line of code but it is throwing an error:
#$Lookup = new-object Microsoft.SharePoint.SPFieldLookupValue($listItem["Business_x0020_Unit"])
new-object : Cannot find type [Microsoft.SharePoint.SPFieldLookupValue]: make sure the assembly containing this type is loaded.
Below is my code.
$loc = "C:\Scripts\ReadListUsingCSOM\dlls" # Location of DLL's
$siteUrl = "https://collaborate.com/"
$listName = "Project"
Set-Location $loc
Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.dll")
Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.Runtime.dll")
#Write-Host "Please enter password for $($siteUrl):"
#$pwd = Read-Host -AsSecureString
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
# Remove or replace line below to change authentication method
#$ctx.Credentials = New-Object System.Net.NetworkCredential($loginname, $pwd)
$web = $ctx.Web
$ctx.Load($web)
$ctx.ExecuteQuery()
$list = $ctx.Web.Lists.GetByTitle($listName)
$caml = new-object Microsoft.SharePoint.Client.CamlQuery
$caml.ViewXML = "<View />"
$listItems = $list.GetItems($caml)
$ctx.Load($listItems);
$ctx.ExecuteQuery();
Write-Host " Current web title is '$($web.Title)', $($web.Url)"
Write-Host $listItems.Count
foreach ($listItem in $listItems)
{
#We have all the list item data. For example, Title.
$Lookup = new-object Microsoft.SharePoint.SPFieldLookupValue($listItem["Business_x0020_Unit"])
[Microsoft.SharePoint.SPFieldLookupValue]$listItem["Business_x0020_Unit"];
Write-Host $listItem.ID $listItem["Project_x0020_Full_x0020_Number"]
}