-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathValidateSystems.ps1
More file actions
155 lines (149 loc) · 5.05 KB
/
ValidateSystems.ps1
File metadata and controls
155 lines (149 loc) · 5.05 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<#
.SYNOPSIS
ValidateSystems
.DESCRIPTION
Validate if a system still exists
.Author
Mick Pletcher
.Date
26 February 2015
.EXAMPLE
powershell.exe -executionpolicy bypass -file ValidateSystems.ps1
#>
Function InitializeGlobalMemory {
Set-Variable -Name Computers -Scope Global -Force
Set-Variable -Name Logfile -Scope Global -Force
Set-Variable -Name RelativePath -Scope Global -Force
Set-Variable -Name Webroot -Scope Global -Force
$Global:Failures = @()
$Global:RelativePath = (split-path $SCRIPT:MyInvocation.MyCommand.Path -parent)+"\"
$Global:LogFile = $Global:RelativePath + "Output.csv"
$Global:Computers = Get-Content -Path $Global:RelativePath"SCCMSystems.txt" -Force
$Global:Webroot = Get-Content -Path $Global:RelativePath"AntivirusSystems.txt" -Force
}
Function ProcessLogFile {
If ((Test-Path $Global:LogFile) -eq $true) {
Remove-Item $Global:LogFile -Force
}
If ((Test-Path $Global:LogFile) -eq $false) {
$temp = New-Item $Global:LogFile -ItemType File -Force
$Output = ","+"Deletions"+","+","+","+"Additions"
Out-File -FilePath $Global:LogFile -InputObject $Output -Append -Force -Encoding UTF8
$Output = "Computer Name"+","+"Active Directory"+","+"SCCM"+","+"Antivirus"+","+"Antivirus"
Out-File -FilePath $Global:LogFile -InputObject $Output -Append -Force -Encoding UTF8
}
}
Function ProcessComputers {
$obj = New-Object PSObject
$Count = 0
Foreach ($Computer in $Global:Computers) {
cls
$Antivirus = $false
$Count += 1
Write-Host "Processing "$Count" of " -NoNewline
Write-Host $Global:Computers.Count
Write-Host
Write-Host "Computer Name: "$Computer
$ADAccount = $null
#Active Directory
Write-Host "Testing AD Presence....." -NoNewline
$ErrorActionPreference = 'SilentlyContinue'
$ADAccount = Get-ADComputer $Computer
If ($ADAccount -eq $null) {
$ADAccount = $false
Write-Host "Does not Exist" -ForegroundColor Red
} else {
$ADAccount = $true
Write-Host "Exists" -ForegroundColor Yellow
}
#Antivirus
Write-Host "Testing Antivirus....." -NoNewline
Foreach ($system in $Global:Webroot) {
If ($system -eq $Computer) {
$Antivirus = $true
}
}
If ($Antivirus -eq $true) {
Write-Host "Exists" -ForegroundColor Yellow
} else {
Write-Host "Does not exist" -ForegroundColor Red
}
#Network Connectivity
Write-Host "Testing Network Connectivity....." -NoNewline
If ((Test-Connection -ComputerName $Computer -Quiet) -eq $false) {
$NetworkTest = ping $Computer
If ($NetworkTest -like '*Ping request could not find host*') {
$NetworkTest = $false
Write-Host "Does not exist" -ForegroundColor Red
} else {
$NetworkTest = $true
Write-Host "Exists" -ForegroundColor Yellow
}
} else {
$NetworkTest = $true
Write-Host "Exists" -ForegroundColor Yellow
}
If (($ADAccount -eq $true) -and ($NetworkTest -eq $false)) {
#Write-Host $Computer -NoNewline
#Write-Host " - Delete from AD and SCCM" -BackgroundColor Yellow -ForegroundColor Black
$obj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer
If ($Antivirus -eq $true) {
$obj | Add-Member -MemberType NoteProperty -Name Action -Value "AD_SCCM_Antivirus"
} else {
$obj | Add-Member -MemberType NoteProperty -Name Action -Value "AD_SCCM"
}
}
If (($ADAccount -eq $false) -and ($NetworkTest -eq $false)) {
#Write-Host $Computer -NoNewline
#Write-Host " - Delete from SCCM" -BackgroundColor Green -ForegroundColor Black
$obj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer
If ($Antivirus -eq $true) {
$obj | Add-Member -MemberType NoteProperty -Name Action -Value "SCCM_Antivirus"
} else {
$obj | Add-Member -MemberType NoteProperty -Name Action -Value "SCCM"
}
}
If (($ADAccount -eq $true) -and ($NetworkTest -eq $true) -and ($Antivirus -eq $false)) {
$obj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer
$obj | Add-Member -MemberType NoteProperty -Name Action -Value "AddAntivirus"
}
If ($obj -ne $null) {
$Global:Failures += $obj
$Output = $obj.ComputerName
If ($obj.Action -eq "AD_SCCM") {
$Output = $Output + ","+"X"+","+"X"
}
If ($obj.Action -eq "AD_SCCM_Antivirus") {
$Output = $Output + ","+"X"+","+"X"+","+"X"
}
If ($obj.Action -eq "SCCM") {
$Output = $Output + ","+","+"X"
}
If ($obj.Action -eq "SCCM_Antivirus") {
$Output = $Output + ","+","+"X"+","+"X"
}
If ($obj.Action -eq "AddAntivirus") {
$Output = $Output + ","+","+","+","+"X"
}
Out-File -FilePath $Global:LogFile -InputObject $Output -Append -Force -Encoding UTF8
Remove-Variable -Name obj
$obj = New-Object PSObject
}
Start-Sleep -Seconds 1
}
}
Function WriteToScreen {
cls
Foreach ($Failure in $Global:Failures) {
If ($Failure -ne $null) {
Write-Output $Failure
}
}
$ErrorActionPreference = 'Continue'
}
cls
Import-Module -Name ActiveDirectory
InitializeGlobalMemory
ProcessLogFile
ProcessComputers
WriteToScreen