none
power shell script to apply validation settings for pages Library to all sites/sub sites/sub sub sites in my site collection. RRS feed

  • Question

  • Please provide the script to update validation settings to entire site collection as well as subsites and sub sub sites.

    This validation should apply to all the sites to check if subsite exists?

    Please provide the script?

    ex:

    Add-PSSnapin Microsoft.SharePoint.PowerShell
    $site=Get-SPSite "http://mysite/"
    $web=$site.RootWeb
     foreach ($Subweb in $web.Webs)
            {        
    $list=$Subweb.Lists["Pages"];
    $list.ValidationFormula = "=[Time Min]<=[Time Max]";
    $list.ValidationMessage = "Please enter the valid Time. Make sure Time Min Value should be less than Max Value.";
    $list.Update();
            }
    write-host $Subweb.Title;

    Monday, March 4, 2019 9:48 AM

All replies

  • Hi sudhir,

    Sample script for your reference, apply all sub sites Pages library validation if there are fields "Time Min" and "Time Max" existed in the library:

    [System.Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)
    [System.Reflection.Assembly]::Load(“Microsoft.SharePoint.Portal, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)
     
    $siteURL = "http://sp/"
    $spSite = [Microsoft.SharePoint.SPSite] ($siteURL)
     
    if($spSite -ne $null)
    {
       foreach($subWeb in $spSite.AllWebs)
       {
          if($subWeb -ne $null)
          {
     
             $spListColl = $subweb.Lists
             foreach($eachList in $spListColl)
             {
                if($eachList.Title -eq "Pages"-and $eachList.Fields.ContainsField("Time Min")-and $eachList.Fields.ContainsField("Time Max"))
                {
                    $eachList.ValidationFormula = "=[Time Min]<=[Time Max]";
    				$eachList.ValidationMessage = "Please enter the valid Time. Make sure Time Min Value should be less than Max Value.";
    				$eachList.Update();
    				
                }
             }
             $subWeb.Dispose()
          }
          else
          {
             Echo $subWeb "does not exist"
          }
       }
       $spSite.Dispose()
    }
    else
    {
       Echo $siteURL "does not exist, check the site collection url"
    }
    Echo Finish

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Tuesday, March 5, 2019 5:22 AM
  • while execute the script,i got Access denied Issue.Please help
    Tuesday, March 5, 2019 9:16 AM
  • Hi sudhir,

    Please make sure current logged in user has permission for all sub sites. You can check permission in Site Pemissions.

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Tuesday, March 5, 2019 9:19 AM
  • Hi,

    You could also create a new site collection and create some subsites with same permission as parent site and then test the code above.

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Tuesday, March 5, 2019 9:20 AM
  • Hi,

     

    I am checking to see how things are going there on this issue. Please let us know if you would like further assistance.

     

    You can mark the helpful post as answer to help other community members find the helpful information quickly.

     

    Thanks

     

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Friday, March 8, 2019 8:29 AM
  • Hi Sudhir,

    Would you please provide a update of this question ?

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Monday, March 18, 2019 6:00 AM