Une question habituelle dans toute gestion de fermes SharePoint est la gestion des sites fantomes.
Pour définir ce que c’est il faut prendre un cas utilsateur simple :
- Un site d’équipe est créé pour partager la documentation autour d’un projet défini
- Plusieurs utilisateurs travaillent pendant des semaines autour de ce projet
- Au bout d’un certain temps ce projet est terminé
- Les utilisateurs sont réaffectés sur d’autres projets
- Au bout d’un temps variable, plus personne ne vient sur ce site et tout le monde oublie son existance
- Le site SharePoint et son contenu passe alors en mode fantome
C’est un très grand classique des TeamSites et le volume occupé par ce type de site peut rapidement être important.
Benoît Jester propose sur son blog une solution (via un script PowerShell) permettant de lister les sites et sous sites avec les dates de dernière modification :
- https://spasipe.wordpress.com/2014/07/23/sharepoint-20xx-script-powershell-permettant-de-lister-les-sites-peu-utilises/
- https://gallery.technet.microsoft.com/SharePoint-200720102013-48c9e2b1
Je suis donc reparti de ce script que j’ai légèrement modifié avec son accord en ajoutant des colonnes au fichier CSV (WEB App, Site Collection, Site Owner, DB, …).
Le résultat final est le suivant:
====================================================================================
# SitesUsage.ps1 - Export 'LastItemModifiedDate' property of each site in a csv file
# Written by Benoît Jester [MVP] - http://spasipe.wordpress.com
# Version 1.0 - 07/18/2014
# ====================================================================================
# Source: https://spasipe.wordpress.com/2014/07/23/sharepoint-20xx-script-powershell-permettant-de-lister-les-sites-peu-utilises/
param(
[Parameter(Mandatory=$False)]
[bool]$displayMessages = $true,
[Parameter(Mandatory=$False)]
[string]$SMTPServer="",
[Parameter(Mandatory=$False)]
[string]$ToEmailAddress="",
[Parameter(Mandatory=$False)]
[string]$FromEmailAddress="",
[Parameter(Mandatory=$False)]
[string]$delimiter=","
)
# Applies Read Access to the specified accounts for a web application
Function Add-UserPolicy([String]$url)
{
Try
{
$webapp = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup("$url")
$user = ([Security.Principal.WindowsIdentity]::GetCurrent()).Name
$displayName = "Sites Usage Read Account"
$perm = "Full Read"
# If the web app is not Central Administration
If ($webapp.IsAdministrationWebApplication -eq $false)
{
# If the web app is using Claims auth, change the user accounts to the proper syntax
If ($webapp.UseClaimsAuthentication -eq $true)
{$user = 'i:0#.w|'+$user}
[Microsoft.SharePoint.Administration.SPPolicyCollection]$policies = $webapp.Policies
[Microsoft.SharePoint.Administration.SPPolicy]$policy = $policies.Add($user, $displayName)
[Microsoft.SharePoint.Administration.SPPolicyRole]$policyRole = $webapp.PolicyRoles | where {$_.Name -eq $perm}
If ($policyRole -ne $null)
{$policy.PolicyRoleBindings.Add($policyRole)}
$webapp.Update()
If($displayMessages)
{Write-Host -ForegroundColor White " Read access applied for `"$user`" account to `"$url`""}
}
}
Catch
{
$_
Write-Warning "An error occurred applying Read access for `"$user`" account to `"$url`""
}
}
# Load assemblies
Function Load-Assemblies
{
Try
{
If ((Get-PsSnapin |?{$_.Name -eq "Microsoft.SharePoint.PowerShell"})-eq $null)
{
If($displayMessages)
{
Write-Host -ForegroundColor Green "-----------------------------------------"
Write-Host -ForegroundColor Green " - Loading SharePoint Powershell Snapin -"
Write-Host -ForegroundColor Green "-----------------------------------------"
}
Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction Stop | Out-Null
}
}
Catch
{
If($displayMessages)
{
Write-Host -ForegroundColor Green "------------------------------------------"
Write-Host -ForegroundColor Green " - Loading Microsoft.SharePoint Assembly -"
Write-Host -ForegroundColor Green "------------------------------------------"
}
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | Out-Null
}
}
# Send Email with log file as attachment
Function SendEmail($attachment)
{
Try
{
If($displayMessages)
{
Write-Host -ForegroundColor White "--------------------------------------------------------------"
Write-Host -ForegroundColor White " Sending Email to $ToEmailAddress with $attachment in attachment."
}
Send-MailMessage -To $ToEmailAddress -From $FromEmailAddress -Subject "Sites Usage - $env:COMPUTERNAME" -SmtpServer $SMTPServer -Attachments $attachment
If($displayMessages)
{Write-Host -ForegroundColor Green " Email sent successfully to $ToEmailAddress"}
}
Catch
{Write-Warning $_}
}
$DateStarted = $(Get-date)
If($displayMessages)
{
Write-Host -ForegroundColor Green "----------------------------------"
Write-Host -ForegroundColor Green "- Script started on $DateStarted -"
Write-Host -ForegroundColor Green "----------------------------------"
}
# Check Permission Level
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{Write-Warning "You don't have Administrator rights to run this script."}
else
{
If($SMTPServer)
{
If (!$ToEmailAddress -or !$FromEmailAddress)
{
Write-Warning "Please specify a 'ToEmailAddress' and a 'FromEmailAddress' parameter."
Exit
}
}
# Load assemblies
Load-Assemblies
# Local variables
$sitesList = $null
$sitesList = @()
# Build structure
$itemStructure = New-Object psobject
$itemStructure | Add-Member -MemberType NoteProperty -Name "Title" -value ""
$itemStructure | Add-Member -MemberType NoteProperty -Name "WebAppURL" -value ""
$itemStructure | Add-Member -MemberType NoteProperty -Name "SiteCollURL" -value ""
$itemStructure | Add-Member -MemberType NoteProperty -Name "SiteCollOwnerEmail" -value ""
$itemStructure | Add-Member -MemberType NoteProperty -Name "SiteCollsecondayAdminEmail" -value ""
$itemStructure | Add-Member -MemberType NoteProperty -Name "ContentDatabase" -value ""
$itemStructure | Add-Member -MemberType NoteProperty -Name "Created" -value ""
$itemStructure | Add-Member -MemberType NoteProperty -Name "SiteCollectionsize" -value ""
$itemStructure | Add-Member -MemberType NoteProperty -Name "WebURL" -value ""
$itemStructure | Add-Member -MemberType NoteProperty -Name "Template" -value ""
$itemStructure | Add-Member -MemberType NoteProperty -Name "Year" -value ""
$itemStructure | Add-Member -MemberType NoteProperty -Name "Month" -value ""
$itemStructure | Add-Member -MemberType NoteProperty -Name "Day" -value ""
$itemStructure | Add-Member -MemberType NoteProperty -Name "LastModifiedDate" -value ""
If($displayMessages)
{
Write-Host -ForegroundColor Green "-----------------------"
Write-Host -ForegroundColor Green " - Scanning All Sites -"
Write-Host -ForegroundColor Green "-----------------------"
}
# Browse sites
$WebSrv = [microsoft.sharepoint.administration.spwebservice]::ContentService
foreach ($webApp in $WebSrv.WebApplications)
{
foreach ($AltUrl in $webapp.AlternateUrls)
{Add-UserPolicy $AltUrl.uri}
foreach ($site in $WebApp.sites)
{
$rootweb = $site.RootWeb;
$SiteAdmin = new-object Microsoft.SharePoint.Administration.SPSiteAdministration($rootweb.URL);
$size = (($SiteAdmin.DiskUsed + 0x80000L) / 0x100000L);
foreach($web in $site.AllWebs)
{
# Build structure
$siteInfos = $itemStructure | Select-Object *;
$siteInfos.Title = $web.Title;
$siteInfos.WebAppURL = $web.Url.Split("/")[2];
$siteInfos.SiteCollURL = $site.URL;
$siteInfos.SiteCollOwnerEmail = $site.Owner.Email;
$siteInfos.SiteCollsecondayAdminEmail = $site.SecondaryContact.Email;
$siteInfos.ContentDatabase = $site.ContentDatabase;
$siteInfos.Created = Get-Date -Date $rootweb.Created;
$siteInfos.SiteCollectionsize = $size;
$siteInfos.WebURL = $web.Url;
$siteInfos.Template = $web.WebTemplate;
$LastModifiedDate = Get-Date -Date $web.LastItemModifiedDate
$siteInfos.Year = $LastModifiedDate.Year;
$siteInfos.Month = $LastModifiedDate.Month;
$siteInfos.Day = $LastModifiedDate.Day;
$siteInfos.LastModifiedDate = $web.LastItemModifiedDate.ToString('d');
$sitesList += $siteInfos;
}
}
$SiteAdmin.Dispose()
$rootweb.Dispose()
}
# CSV Export
If($displayMessages)
{
Write-Host -ForegroundColor Green "---------------"
Write-Host -ForegroundColor Green " - CSV Export -"
Write-Host -ForegroundColor Green "---------------"
}
$sitesList | Where-Object {$_} | Export-Csv -Delimiter "$delimiter" -Path "SitesUsage.csv" -notype
If($displayMessages)
{Write-Host "Export file 'SitesUsage.csv' successfully generated."}
# Email notification
If($SMTPServer)
{SendEmail "SitesUsage.csv"}
# End
If($displayMessages)
{
Write-Host -ForegroundColor Green "---------------------------------"
Write-Host -ForegroundColor Green "- Script started : $DateStarted -"
Write-Host -ForegroundColor Green "- Script finished : $(Get-date) -"
Write-Host -ForegroundColor Green "---------------------------------"
}
Exit
}
Une fois le fichier exécuté vous obtenez un fichier CSV qu’il est possible de charger dans Excel via l’import de données:
Mode delimited et Data + headers, puis sélectionne la vigule (séparateur par défaut):
On peut cliquer sur Finish.
Une fois les données chargées dans Excel, il faut juste sélectionner toute la zone de ce tableau et cliquer sur “Table” dans “Insert”:
On sélectionne le même tableau et dans Insert, on choisit PivotTable, puis en quelques clicks, on obtient ce type de résultat :
Il ne vous reste plus qu’à contacter les propriétaires de site pour les questionner sur la nécessiter de nettoyer leur contenu.
Romelard Fabrice [MBA]
Commentaires
Enregistrer un commentaire