0

I need a script to retrieve the parent-list from a lookup-column. I've already made a script to list all the lists with a lookup column, but I want to know from where the lookup column gets his data. This is what I've got already: The output gives the url, the list-name and the lookup-columnname.

$TTNExcludeLists = "Solution Gallery", 
            "Workflow Tasks", 
            "Master Page Gallery"

Get-SPSite -Limit All | Get-SPWeb -Limit All | 
  Select -ExpandProperty Lists | 
  Where { -Not ($TTNExcludeLists -Contains $_.Title) } | 
  Select -ExpandProperty Fields | 
  Where { $_.TypeDisplayName -eq "Lookup" -and 
          $_.Hidden -eq $false -and 
          $_.FromBaseType -eq $false } | 
  Select {$_.ParentList.ParentWebUrl}, 
         {$_.ParentList}, 
         Title | Sort-Object Title | Format-table -AutoSize -wrap
0

You should use SPFieldLookup.LookupList property to get related list GUID and then use SPListCollection indexer to get this list. Remember to cast this property to Guid before (it's string representation), to use correct indexer.

  • Thanks for the answer, but isn't that just for C# & VB? I can't seem to find a good example in Powershell. – Staf Pinoy Feb 24 '17 at 8:59
  • Definitely not. PowerShell is based on .NET, so generally if you can use some class in C#, you can use it in PowerShell too. When you use SharePoint snap-in and cmdlets like Get-SPSite, you just get standard SSOM object (SPSite in this case) and you can operate on it like in C# (but of course syntax can differ a little). – Paweł Hawrylak Feb 24 '17 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.