-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDC-EVTsys_GITHUB.ps1
77 lines (43 loc) · 1.96 KB
/
DC-EVTsys_GITHUB.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
<##
FOR GITHUB PURPOSES I'M REMOVING ANY SENSITIVE FILE NAMES OR LOCATION NAMES
I have the working script, but in this case I will use ** on sensitive areas
##>
Set-ExecutionPolicy Unrestricted
try
{
$DCs = Get-ADDomainController -Server CLC-**1.domain.edu -Filter *
##$DC = Get-ADDomainController -Server CLC-**1.domain.edu -Filter {HostName -eq "MA-**1.College.domain"}
$Credential = Get-Credential
foreach($DC in $DCs){
Write-Host "################## " $DC.Name " Begin ##################" -ForegroundColor DarkGreen
$Status = Test-Connection -ComputerName $DC.Name -Quiet
If($Status -eq $False) {
Write-Host $DC.Name + " is offline. Continueing to next DC." -ForegroundColor Yellow
Continue
}
$NewSession = New-PSSession -ComputerName $DC.Name -Credential $Credential -ErrorAction Continue
Enter-PSSession -Session $NewSession -ErrorAction Continue
$destinationFile = "\\" + $DC.Name + "\C$\Windows\System32\evtsys.exe"
$TestPath = Test-Path $destinationFile
if ($TestPath -eq $False)
{
Write-Host "Copying EVTSYS.exe to DC" -ForegroundColor Yellow
$Copydestination = "\\" + $DC.Name + "\C$\Windows\System32"
Robocopy.exe \\College.domain\NetLogon $Copydestination evtsys.exe /ZB
}
Start-Process evtsys.exe -ArgumentList {-i -h 172.0.0.0} #172.**.**.**
Restart-Service -Name evtsys
Exit-PSSession
Remove-PSSession $NewSession
Write-Host "################## " $DC.name " End ##################" -ForegroundColor Green
}
Write-Host "################ COMPLETE ################" -ForegroundColor Cyan
}
## Catches any errors
Catch
{
Write-Error $_
$ErrorMessage = $_
$DC.Name | Export-csv -Path "~\desktop\DC-Fail-List.csv" -NoTypeInformation -Append
$ErrorMessage | Export-csv -Path "~\desktop\DC-Fail-List.csv" -NoTypeInformation -Append
}