SharePoint LastItemUserModifiedDate

Wrote a short script that list all SharePoint sites in your Office 365 tennant with the LastItemUserModifiedDate. Could be handy to see if some sites are not used anymore.

First i used Get-SPOSite and LastContentModified, but after some research it turned out that it was not so reliable:
https://social.msdn.microsoft.com/Forums/office/en-US/6e264b4e-e4b4-4b46-a7b0-9686c0f6128e/lastcontentmodifieddate-is-not-giving-me-the-right-values-for-site-collections-sharepoint-online?forum=sharepointdevelopment

My script is a modified version of this one:
https://farhanfaiz.wordpress.com/2017/05/25/sharepoint-online-list-of-sites-webs/

Could be possible you need to add something to your PS $profile if you get a excecution error:
https://www.spjeff.com/2016/08/07/fixed-403-executequery-csom-sharepoint-server/

$tenantAdmin = "admin@contoso.com"
$secureAdminPassword = Read-Host -AsSecureString "Enter password"
$SharePointUrls = Get-SPOSite
$List = @()

foreach($SharePointUrl in $SharePointUrls.URL){
    function AuthenticateUserProfile($siteUrl, $tenantAdmin, $secureAdminPassword) {
        $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SharePointUrl)
        $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($tenantAdmin, $secureAdminPassword)
        $ctx.Credentials = $credentials
        return $ctx
    }

    $ctx = AuthenticateUserProfile $SharePointUrl $tenantAdmin $secureAdminPassword;
    $web = $ctx.Web
    $ctx.Load($web)
    $ctx.ExecuteQuery()

    $Object=[PSCustomObject]@{
        URL = $SharePointUrl
        LastItemUserModified = $web.LastItemUserModifiedDate | get-date -format "yyyy.MM.dd hh:mm"
        }#EndPSCustomObject

    $List+=$object
}

$List | Sort-Object URL

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s