Question

I’ve a list called “A” in root SharePoint online site collection and it have no. of columns. One of the column, say “xyz” is type of “Hyperlink” field which contains the Sub Site URL with display text, like that I’ve total of 30 list items in the list “A”, that means total I will be having 30 sub site URL’s. And, each sub site will have the list name called “Revenue”.

Now my requirement is, I need to iterate through each entry in the list “A” of site collection, and check if the “Hyperlink” field have the site URL. If it has site URL, then I need to hide the list called “Revenue” in that particular sub site using Pnp PowerShell script.

Below is my basic code to hide the list. Could you please help on how to iterate through the list and hide the list “Revenue” if it has the site URL in the list column “xyz”?

$listName = "LIST NAME"
$site = "https://CONTOSO.sharepoint.com/"

Connect-PnPOnline -Url $site -UseWebLogin
Set-PnPList -Identity $listName -Hidden $true

Thank you!!

Was it helpful?

Solution

Test script for your reference:

    $username = "amos@contoso.onmicrosoft.com"
    $password = "password"
    $cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $(convertto-securestring $Password -asplaintext -force)
    Connect-PnPOnline -Url https://contoso.sharepoint.com/sites/dev -Credentials $cred
    $items=(Get-PnPListItem -List "test3" -Fields "xyz","Id").FieldValues
    foreach($item in $items){
   
    Connect-PnPOnline -Url $item["xyz"].Url -Credentials $cred
    Set-PnPList -Identity Revenue -Hidden $true
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top