This repository was archived by the owner on Mar 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ps1
More file actions
76 lines (59 loc) · 2.22 KB
/
Copy pathutils.ps1
File metadata and controls
76 lines (59 loc) · 2.22 KB
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
function error-exit($msg) {
Write-Warning $msg
if ($Host.Name -eq "ConsoleHost") {
Write-Host "Press any key to exit..."
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyUp") > $null
}
exit $false
}
function Ensure-AdminCredentials() {
if ($Global:bdsu_admin_credentials) {
return
}
while(!$Global:bdsu_admin_credentials) {
$credentials = Get-Credential
if (!$? -or !$credentials -or !$credentials.UserName) {
error-exit "Keine Zugangsdaten angegeben, abbrechen..."
}
Connect-AzureAD -Credential $credentials
if (!$?) {
Write-Warning "Verbindung zu Azure AD mit eingegebenen Zugangsdaten fehlgeschlagen."
continue
}
$Global:bdsu_admin_credentials = $credentials
}
}
function Ensure-AzureAD() {
Ensure-AdminCredentials
Connect-AzureAD -Credential $Global:bdsu_admin_credentials
}
function Ensure-ExchangeCommands() {
$sessions = Get-PSSession
if ($sessions.ComputerName -contains "outlook.office365.com") {
return
}
Ensure-AdminCredentials
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Global:bdsu_admin_credentials -Authentication Basic -AllowRedirection
if (!$? -or !$session) {
error-exit "Konnte Exchange-Session nicht erstellen"
}
Import-PSSession $session
if (!$?) {
error-exit "Konnte Exchange-Session nicht importieren"
}
}
function Get-MailboxSizes($domain) {
Ensure-ExchangeCommands
$mailboxes = Get-Mailbox -ResultSize Unlimited | Where-Object {$_.EmailAddresses -like "*@$domain"}
$stats = $mailboxes.userPrincipalName | Get-MailboxStatistics
$sum = 0
$stats | ForEach-Object {
$sum += $_.TotalItemSize.Value -replace "^.*\((.*) bytes\)",'$1' -replace ",",""
[psCustomObject]@{
stat = $_
size = [double]($_.TotalItemSize.Value -replace "^.*\((.*) bytes\)",'$1' -replace ",","")
}
} | sort size | ForEach-Object {$_.stat} | ft DisplayName,ItemCount,TotalItemSize,LastLogonTime
$total = [math]::Round($sum / 1024 / 1024 / 1024, 2)
Write-Host "Total: $total GB"
}