Asked by:
power shell script to apply validation settings for pages Library to all sites/sub sites/sub sub sites in my site collection.

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;
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.- Proposed as answer by Wendy DZMicrosoft contingent staff, Moderator Thursday, March 7, 2019 2:11 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. -
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. -
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. -
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.