1

I want to write one script in STSADM which checks SharePoint 2007 site collection lock status and if any site status is locked/Read-Only/Adding Content Prevented/No Access then the script will Unlock that site.

Following command to check site status: stsadm -o getsitelock -URL Siteurl

Following command for unlock site: stsadm -o setsitelock SiteURL -lock none

I have a list of the site collection in the text file.

Now I need help how to write these in a script and schedule them via Task Scheduler job. In addition, I want to add email sending functionality in the same script if any site gets locked.

1 Answer 1

0

here is a script, schedule it under Farm Administrator with PSShellAdmin privilegies. You can do enum all sites or just at start load your file with sites in $Sites.

asnp *sharepoint* 
$Sites = Get-SPSite -Limit All

foreach($Site in $Sites)
{
    $Lock = STSADM.exe -o getsitelock -Url $Site.Url
    $Lock[1]
    if($Lock[1] -eq '<SiteLock Lock="none" />')
    {
        Write-Host "$($Site.Url) OK" -ForegroundColor Green
    }
    else
    {
        STSADM.exe -o setsitelock -Url $Site.Url -lock none
        Write-Host "$($Site.Url) was unlocked" -ForegroundColor Yellow
    }
}

Hope it helps!

Your Answer

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

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