<#
.Synopsis
Check and Updates sharing settings confirm the new policy
.DESCRIPTION
This script will check and Update the sharing settings confirm the new policy
.EXAMPLE
.\SetSharingMethods.ps1 -siteUrl "https://mytenant.sharepoint.com/teams/T2017_88001-TST" -requestEmail "jurgen.wiersema@ka.bla.nl" -sharingEnabledInt 1 -allowMembersEditMembershipInt 1
#>
Param
(
# The SharePoint site url to run this script on
[Parameter(Mandatory = $true, Position = 1)]
[ValidateNotNullOrEmpty()]
[string]
$siteUrl,
# The request access email address to set in the site
[Parameter(Mandatory = $true, Position = 2)]
[string]
$requestEmail,
# 0 to disable sharing and 1 to enable sharing
[Parameter(Mandatory = $true, Position = 3)]
[ValidateNotNullOrEmpty()]
[ValidateSet(0,1)]
[int]
$sharingEnabledInt,
[Parameter(Mandatory = $true, Position = 4)]
[ValidateNotNullOrEmpty()]
[ValidateSet(0,1)]
[int]
$allowMembersEditMembershipInt
)
function checkSharing($web, $requestEmail, $sharingEnabled, $allowMembersEditMembership) {
#disable request email
$web.RequestAccessEmail = $requestEmail
#set sharing for members
$web.MembersCanShare = $sharingEnabled
$web.Update();
$web.Context.Load($web);
$web.Context.ExecuteQuery();
$group = $web.AssociatedMemberGroup;
$web.Context.Load($group);
$web.Context.ExecuteQuery();
$web.MembersCanShare = $sharingEnabled;
$group.AllowMembersEditMembership = $allowMembersEditMembership;
$group.Update();
$web.Update();
$web.Context.Load($group);
$web.Context.Load($web);
$web.Context.ExecuteQuery();
}
try {
$cred = Get-AutomationPSCredential -Name "SHAREPOINTADMIN";
Connect-PnPOnline -Url $siteUrl -Credentials $cred;
Write-Output "Check site: $($siteUrl)";
$rootweb = Get-PnPWeb;
$sharingEnabled = $false;
$allowMembersEditMembership = $false;
if ($sharingEnabledInt -eq 0)
{
$sharingEnabled = $false;
}
else
{
$sharingEnabled = $true;
}
if ($allowMembersEditMembershipInt -eq 0)
{
$allowMembersEditMembership = $false;
}
else
{
$allowMembersEditMembership = $true;
}
if ($requestEmail -eq 'empty')
{
$requestEmail = "";
}
Write-Output "Setting sharing to $sharingEnabled , allow members to edit memberschip to $allowMembersEditMembership and email to $requestEmail on site $siteUrl";
#check sharing policy
checkSharing -web $rootweb -requestEmail $requestEmail -sharingEnabled $sharingEnabled -allowMembersEditMembership $allowMembersEditMembership;
Write-Output "Script finished succesfully.";
}
catch {
$ErrorMessage = $_.Exception.Message;
Write-Output $ErrorMessage;
Write-Output "Script finished with error.";
}
Hey, great blog, but I don’t understand how to add your site in my reader. Can you Help me please?
ReplyDeleteCheck site
The first casualty of war is the truth
ReplyDeletethe full report