-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParseTeamsAndSharePoint.ps1
99 lines (93 loc) · 3.04 KB
/
ParseTeamsAndSharePoint.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string[]]
$SharePointSitesExports,
[Parameter(Mandatory = $true)]
[string[]]
$TeamsExports,
[Parameter(Mandatory = $true)]
[string]
$ShareTeamsUrlListFile
)
BEGIN{
$DATE = Get-Date -Format yyyy_MM_dd
}
PROCESS{
$SharePoint = $SharePointSitesExports | ForEach-Object {
if ($_.EndsWith("csv")) {
Import-CSV $_
}
else {
Import-Clixml $_
}
}
$SharePoint = $SharePoint | Group-Object -Property "Title" -AsHashTable
$Teams = $TeamsExports | ForEach-Object {
if ($_.EndsWith("csv")) {
Import-CSV $_
}
else {
Import-Clixml $_
}
}
$Teams = $Teams | Group-Object -Property "DisplayName" -AsHashTable
$Sites = Get-Content -LiteralPath $ShareTeamsUrlListFile
$Total = $Sites | Measure-Object | Select-Object -ExpandProperty Count
$SharePointAndTeams = @()
foreach ($Site in $Sites){
$SharePointAndTeams += $SharePoint[$site]
}
$SharePointAndTeams = $SharePointAndTeams | Sort-Object -Unique -Property URL
$Results = @()
foreach ($Site in $SharePointAndTeams){
$Title = $Site.Title
$Template = $Site.Template
$Size = [int]$Site.StorageUsageCurrent * 1MB / 1GB
if ($Title -eq "MCSB Licensing"){
$Title = "MCSB Licensing Section"
$Notes = "Team site was renamed from 'MCSB Licensing' to 'MCSB Licensing Section'"
}
else{
$Notes = ""
}
$InTeams = $Teams.ContainsKey($Title)
if($InTeams){
$SiteType = "Teams"
}
elseif ($Template -eq "STS#3") {
$SiteType = "SharePoint"
}
elseif($Template -eq "TEAMCHANNEL#0") {
$SiteType = "Teams Private Channel"
}
else{
$SiteType = "SharePoint"
}
$Results += [PSCustomObject]@{
Title = $Title
URL = $Site.URL
SiteType = $SiteType
Agency = $Site.Agency
"Size GB" = $([math]::Ceiling($Size))
Notes = $Notes
}
}
$Group_Results = $Results | Group-Object -Property Agency
$Count = $Group_Results | Measure-Object -Sum -Property Count | Select-Object -ExpandProperty Sum
foreach ($Group in $Group_Results){
$Agency = $Group.Name
$OutputFile = "$($Agency)_Master_SharePoint_And_Teams_$DATE.xlsx"
foreach ($SiteType in @("SharePoint", "Teams")){
$SheetName = $SiteType
$Result = $Group.Group | Where-Object {$_.SiteType -like "$($SiteType)*"}
$Result | Select-Object Title, Url, SiteType, "Size GB", Notes | Export-Excel -Path $OutputFile -WorksheetName $SheetName -AutoSize -FreezeTopRow -AutoFilter
}
}
if($Total -ne $Count){
Write-Host "Numbers don't match. Total $Total. Processed $Count" -ForegroundColor Red
}
else{
Write-Host "All mailboxes processed. Total $Total" -ForegroundColor Green
}
}