-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParseMasterFiles.ps1
69 lines (62 loc) · 2.39 KB
/
ParseMasterFiles.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
[CmdletBinding()]
param (
[Parameter(Mandatory = $True)]
[string]
$Path
)
BEGIN {
$DOMAINS = @{
CDFA = @('cdfa.ca.gov', 'cdfao365.onmicrosoft.com')
CDPH = @('cdph.ca.gov', 'cdph.onmicrosoft.com')
DCA = @('dca.ca.gov', 'dcao365.onmicrosoft.com')
}
$DATE = Get-Date -Format yyyy_MM_dd
}
PROCESS {
$Master_files = Get-ChildItem -Path $Path -File -Filter "Master_*.csv" | Where-Object { $_.name -notlike "*original*" }
$Mailbox_Types = @(
'User',
'Shared',
'Room',
'Equipment'
)
$Total = $Master_files | ForEach-Object {Import-Csv $_.FullName} | Measure-Object | Select-Object -ExpandProperty Count
$Count = 0
$Output_Results = $()
foreach ($T in $Mailbox_Types) {
$File = $Master_files | Where-Object { $_.Name -like "*$T*" }
$CSV = Import-Csv $File.FullName
$Count = $Count + ($CSV | Measure-Object | Select-Object -ExpandProperty Count)
foreach ($A in @("CDFA", "CDPH", "DCA")){
$OutputFile = "$($A)_Master_Mailbox_List_$DATE.xlsx"
$SheetName = "$T Mailboxes"
$Tenant_Domains = $DOMAINS[$A]
$Result = $CSV | Where-Object {$_.OldUPN -like "*$($Tenant_Domains[0])" -or $_.OldUPN -like "*$($Tenant_Domains[1])"}
$Result = $Result | Select-Object @{n="Source Mailbox";e={$_.OldUPN}}, @{n="Target Mailbox";e={$_.UPN}} | Sort-Object -Property "Source Mailbox"
$Result | Export-Excel -Path $OutputFile -WorksheetName $SheetName -AutoSize -FreezeTopRow -AutoFilter
$Output_Results += @("$A | $($T): $($Result | Measure-Object| Select-Object -ExpandProperty Count)")
}
}
$CDFA_Total = 0
$CDPH_Total = 0
$DCA_Total = 0
$Output_Results = $Output_Results | Sort-Object
foreach ($R in $Output_Results){
$A = ($R -split ' ')[0]
[int]$t = ($R -split ' ')[-1]
if($A -eq 'CDFA'){$CDFA_Total += $t}
elseif ($A -eq 'CDPH') {$CDPH_Total += $t}
elseif($A -eq 'DCA'){$DCA_Total += $t}
Write-Host $R
}
Write-Host "CDFA Total: $CDFA_Total"
Write-Host "CDPH Total: $CDPH_Total"
Write-Host "DCA Total: $DCA_Total"
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
}
}
END {}