-
Notifications
You must be signed in to change notification settings - Fork 0
/
OneDriveDeltasCheck.ps1
55 lines (52 loc) · 2.09 KB
/
OneDriveDeltasCheck.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
#get the changes to OneDrive files and log the results
$LogPath = Join-Path -Path $PSScriptRoot -ChildPath "logs"
if (-not(Test-Path $LogPath)) {
New-Item -Path $LogPath -ItemType Directory -Force
}
$LogFile = Join-Path -Path $LogPath -ChildPath "OneDriveModifyNewRemoveLog-$(Get-Date -Format 'yyyyMMdd-HHmmss').txt"
$XmlFile = Join-Path -Path $LogPath -ChildPath "OneDriveModifyNewRemoveXml-$(Get-Date -Format 'yyyyMMdd-HHmmss').xml"
try {
#run the script to generate the deltas
$OneDriveDeltas = & (Join-Path -Path $PSScriptRoot -ChildPath "OneDriveDeltasOutput.ps1")
if ($OneDriveDeltas) {
$OneDriveDeltas | Export-Clixml -Path $XmlFile -Force -ErrorAction Stop
$OneDriveDeltas | ConvertTo-Csv -NoTypeInformation -ErrorAction Stop | Out-File -FilePath $LogFile -Force -ErrorAction Stop
}
}
catch {
throw $_
}
#email the results
$to = "[email protected]"
$from = "[email protected]"
if ($OneDriveDeltas) {
# $Credential = New-Object System.Management.Automation.PSCredential -ArgumentList '[email protected]', $('XXXXX' | ConvertTo-SecureString -AsPlainText -Force)
# $Credential = Get-Credential
if (-Not(Get-Command -Name Get-sjPassword -ErrorAction SilentlyContinue)) {
. (Join-Path -Path $PSScriptRoot -ChildPath .\Get-sjPassword-Function.ps1)
}
$Credential = Get-sjPassword -UserName "[email protected]"
$Body = @"
Report save location: $LogFile
Object save location: $XmlFile
$(Get-Content -Path $LogFile | Out-String)
"@
$Params = @{
Body = $Body #"Report save location: $XmlFile `n`n$(Import-Clixml -Path $XmlFile | Format-Table -AutoSize | Out-String)"
To = $to
From = $from
Subject = "OneDrive Automation Report on $(Get-Date -Format 'yyyyMMdd-HHmmss')"
SmtpServer = 'smtp.live.com'
Port = "587"
Credential = $Credential
UseSsl = $true
ErrorAction = "Stop"
}
try {
Send-MailMessage @Params
& (Join-Path -Path $PSScriptRoot -ChildPath "OneDriveDeltasUpdate.ps1")
}
catch {
throw $_
}
}