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:

My script is a modified version of this one:

Could be possible you need to add something to your PS $profile if you get a excecution error:

$tenantAdmin = "[email protected]"
$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

        URL = $SharePointUrl
        LastItemUserModified = $web.LastItemUserModifiedDate | get-date -format "yyyy.MM.dd hh:mm"


$List | Sort-Object URL

Leave a Reply

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

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

Facebook photo

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

Connecting to %s