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


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
  • 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.
    – taruki_MS
    Commented Aug 3, 2020 at 6:49
  • Does Connect-PnPOnline -Url $site -UseWebLogin report an error?
    – Amos
    Commented Aug 3, 2020 at 7:08
  • UseWebLogin working as expected.. Thank you!!
    – taruki_MS
    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.
    – taruki_MS
    Commented Aug 4, 2020 at 9:22
  • This should be controlled by permission.You could try to set the list has unique permission.
    – Amos
    Commented Aug 4, 2020 at 9:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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