-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathget-unifiedgroups.ps1
77 lines (66 loc) · 2.82 KB
/
get-unifiedgroups.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
<#
----------------------------------------------------
get-unifiedgroups.ps1
Script by atwork.at, Martina Grom, v1, 2016-08-02
This scripts reads all groups of an Office 365 tenant
and outputs the details inclusive used storage into a CSV file for further use (with Excel).
For details about unified groups and limits see:
https://blogs.msdn.microsoft.com/tomvan/2015/08/12/office-365-groups-introduction-frequently-asked-questions/
!! First, run get-unifiedgroups-connect.ps1 !!
----------------------------------------------------
#>
# Specifies the location where the result files shall be saved
$ResultFile = '.\get-unifiedgroups.csv'
#----------------------------------------------------
# Get all Office 365 groups of the tenant: $groups = Get-UnifiedGroup
# But we need only specific properties including the lookup of the manager done by the Cmdlet itself.
$groups = Get-UnifiedGroup -ResultSize Unlimited | Select-Object Name,Alias,PrimarySmtpAddress,AccessType,SharePointSiteUrl,SharePointDocumentsUrl,@{n='Manager';e={$(get-recipient -Identity $($_.managedby[0])).primarysmtpaddress} }
# use my own structure for combining the result
Class line
{
[String]$Number
[String]$Name
[String]$PrimarySmtpAddress
[String]$AccessType
[String]$Manager
[String]$SharePointSiteUrl
[String]$SharePointDocumentsUrl
[String]$StorageQuota
[String]$StorageUsageCurrent
[String]$WebsCount
[String]$LastContentModifiedDate
}
# add each group to the result
Write-Output "Running..."
$all=@()
$i=0
Foreach ($group in $groups) {
$i ++
Write-Output "$($i). $($group.Alias)"
# properties we always have...
$c = New-Object line
$c.Number = $i
$c.Name = $group.Alias
$c.PrimarySmtpAddress = $group.PrimarySmtpAddress
$c.AccessType= $group.AccessType
$c.Manager = $group.Manager
$c.SharePointSiteUrl = 'not provisioned'
# add and overwrite following data only, if a SharePoint Site is provisioned for this group.
if ($group.SharePointSiteUrl -ne $null) {
$SPOSite = (Get-SPOSite -Identity $group.SharePointSiteUrl)
$c.SharePointSiteUrl = $group.SharePointSiteUrl
$c.SharePointDocumentsUrl = $group.SharePointDocumentsUrl
$c.StorageQuota = $SPOSite.StorageQuota
$c.StorageUsageCurrent = $SPOSite.StorageUsageCurrent
$c.LastContentModifiedDate = $SPOSite.LastContentModifiedDate
$c.WebsCount = $SPOSite.WebsCount
}
$all += $c
}
# Delete the $ResultFile if existing and output
if (Test-Path $ResultFile) {
Remove-Item -Path $ResultFile -Force
}
Write-Output $all | Export-Csv -Path $ResultFile -NoClobber -NoTypeInformation -Encoding UTF8 -Force -Delimiter ','
Write-Output "Done. $($groups.Count) groups. Details saved to $($ResultFile)"
# end of script.