We help IT Professionals succeed at work.

PowerShell script to set a large number of SharePoint 2013 site collections to "No Access" lock status

I have several hundred sites on my SharePoint 2013 farm that I need to set to "No Access" by locking the site collection.  What I would like to do, is use a PowerShell script to read the list of URL's from a text file, loop through each one, and lock the site collection.  This is what I have so far, but need some assistance on getting it completed:

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
 
$Sites = Get-Content -Path e:\scripts\SitesToLock.txt
 
ForEach ($site in $Sites) 
{
  Set-SPSite -Identity $site.Url -LockState "NoAccess" }

Open in new window

Comment
Watch Question

A lack of information provides a lack of a decent solution.
Commented:
Your variables are wrong.

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
 
$Sites = Get-Content -Path e:\scripts\SitesToLock.txt
 
ForEach ($site in $Sites) {Set-SPSite -Identity $site -LockState "NoAccess"}

Open in new window


You don't need the .URL bit since you're not importing from a CSV and as such, doesn't have a header.
Tray896SharePoint Engineer

Author

Commented:
Doh, thanks!