Hello charles-gerardlemetayer,
Thank you for your answer.
I thought that it would be possible to export in a csv the results of step 1 then execute another script by inputing the csv.
Otherwise thank you for your answers !
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
I need some help please !
I'd like to create a script which would execute the following steps :
I managed to do steps 1 but doesn't have the skills to execute steps 2 and 3.
Here is the script I'm using for step 1 :
I $webApp = Get-SPWebApplication “WEB APPLICATION URL”
$daysInActive = Read-Host “Enter in number of days to check since last modified”
$date = (Get-Date).AddDays(-$daysInActive).ToString(“MM/dd/yyyy”)
Foreach ($web in $webApp | Get-SPSite -Limit All | Get-SPWeb -Limit All)
{
if ($web.LastItemModifiedDate -le $date)
{
Write-Host $web.Url
Write-Host $web.LastItemModifiedDate
$web.Url + ” | ” + “Last Modified Date: ” + $web.LastItemModifiedDate >> LastModified.txt
}
}
Any help wouldbe much appreciated.
Thank you very much
Best regards,
Andy
Hello charles-gerardlemetayer,
Thank you for your answer.
I thought that it would be possible to export in a csv the results of step 1 then execute another script by inputing the csv.
Otherwise thank you for your answers !
Hello,
Regarding "3) Delete locked inactive sites after 200 days", is it 200 days after locked site by the script?
I'm a bit confuse regarding your goal. Are you trying to lock inactive site collections or inactive sub-sites in site collections?
I'm not a Sharepoint expert, but as far I can see :
Regards,
Charles
We could traverse web application, site collection, site like this(If the site was modified within 100 days, site collection will not be locked):
$WebApps = Get-SPWebApplication
$daysInActive =100;
$date = (Get-Date).AddDays(-$daysInActive).ToString("MM/dd/yyyy")
foreach($webApp in $WebApps) {
foreach ($spSite in $webApp.Sites) {
$check=$true;
foreach($spWeb in $SPsite.AllWebs) {
if($spWeb.LastItemModifiedDate -ge $date){
$check=false;
}
}
if($check){
Set-SPSite -Identity $spSite -LockState "NoAccess"
}
}
}
The third requirement should be difficult to achieve, there is no attribute value to store the lock time.
Hello charles-gerardlemetayer, Hello AmosWu-MSFT,
Thank you for your replies.
"3) Delete locked inactive sites after 200 days", is it 200 days after locked site by the script?",
Yes, I would like to delete locked site from step 2, maybe with a second script which input all the locked sites ?
Thank you very much for your help.
Hello,
As explained by @Amos Wu-MSFT , there're no value about lock time.
Possible workaround : you can create a NoSQL Database (as a Json file), which could be loaded when script start - or in another process, which contains the website ID, name and lock date.
Another solution : you can add a tag in the website name as "INACTIVELOCKED-DDMMYYYY-SiteName".
Then, you will have to split name by "-" symbole, where [0] is the process, [1] the locked date.