Wednesday, 6 February 2019

Lock/ Unlock sites


Lock/UnLock sites:

Add-PSSnapin Microsoft.SharePoint.Powershell
$CurrentDirectory =  Split-Path -parent $MyInvocation.MyCommand.Definition
$Sites= Get-content "$CurrentDirectory\R2Readonly\sitename.txt";
#$Sites= Get-content "$CurrentDirectory\R2Readonly\R2sitename.txt";

Add-Content -Path $logpath -Value ("SiteCollection Url"+","+"Site Owner" )

$input = read-host "Please enter 1 to lock and 2 for unlock sites"
foreach ($site in $Sites)
{
    if($input -eq 1)
    {
         Set-SPSite -Identity $site -LockState "ReadOnly"
        write-host $site " locked" -BackgroundColor Yellow -ForegroundColor Red
      }
   if($input -eq 2)
    {
    
        Set-SPSite -Identity $site -LockState "Unlock"
        write-host $site " Unlock" -BackgroundColor Yellow -ForegroundColor Red
    }
}

No comments:

Post a Comment