-
Notifications
You must be signed in to change notification settings - Fork 0
/
MonitorDeployer.ps1
74 lines (67 loc) · 1.6 KB
/
MonitorDeployer.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
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2016 v5.2.129
Created on: 2016-10-30 20:56
Created by: Scorpion
Organization:
Filename: OverMon.ps1
===========================================================================
.DESCRIPTION
A Script that used to sync scripts, tasks and files from a configuration server and then make a sucessful mark on them.
This script should be configured to run regularly.
#>
#region Functions
function Get-ADSIComputerSite
{
[System.DirectoryServices.ActiveDirectory.ActiveDirectorySite]::GetComputerSite()
}
Function Touch-File
{
$file = $args[0]
if($file -eq $null) {
throw "No filename supplied"
}
if(Test-Path $file)
{
(Get-ChildItem $file).LastWriteTime = Get-Date
}
else
{
echo $null > $file
}
}
#endregion
function Pull-Configuration
{
param
(
[array]$serverList,
[String]$configPath = 'ExchangeMonitor\Configuration',
[String]$markPath = 'ExchangeMonitor\MonMarks',
[String]$localPath = 'D:\ExchangeMonitor'
)
$siteName = (Get-ADSIComputerSite).Name
$sucess = $false
foreach ($server in $serverList) {
if (Test-Path "\\$server\$configPath\")
{
$list = Get-ChildItem "\\$server\$configPath\*.zip"
foreach ($Taskfile in $list) {
Copy-Item $Taskfile -Destination $localPath
}
Touch-File "\\$server\$markPath\$siteName"
break
}
}
if ($sucess)
{
return $config
}
else
{
return $null
}
}
#Main
$config = Pull-Configuration -serverList DC1,DC2