0

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!!

1 Answer 1

1

Test script for your reference:

    $username = "[email protected]"
    $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
    }
5
  • Thanks for your quick help. I tried the above script by giving our user name and password but script throwing the below error as it's enable MFA authentication which additionally sent a OTP to registered mobile number. Could you please help how to handle MFA? Error: Connect-PnPOnline : The sign-in name or password does not match one in the Microsoft account system. Commented Aug 3, 2020 at 6:49
  • Does Connect-PnPOnline -Url $site -UseWebLogin report an error? Commented Aug 3, 2020 at 7:08
  • UseWebLogin working as expected.. Thank you!! Commented Aug 4, 2020 at 3:38
  • Is there a way to hide the list for others except for owners group in power-shell? I need to show the list only for owners, and not to others. Commented Aug 4, 2020 at 9:22
  • This should be controlled by permission.You could try to set the list has unique permission. Commented Aug 4, 2020 at 9:36

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.