-
Notifications
You must be signed in to change notification settings - Fork 0
/
_autoinstall.PS1
353 lines (268 loc) · 11.1 KB
/
_autoinstall.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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
#Yevgen Volchenko
#eu9591
###########
#Hardening#
###########
function Set-Admins
{
param([Parameter(Mandatory=$true)] $password)
$adsi = [adsi]"WinNT://$env:Computername"
$evryadm = $adsi.Children | where {$_.Name -eq "evryadm"}
if (!$evryadm)
{
$evryAdm = $adsi.create('User','evryadm')
$bSTR = [system.runtime.interopservices.marshal]::SecureStringToBSTR($password)
$_password = [system.runtime.interopservices.marshal]::PtrToStringAuto($BSTR)
$evryAdm.SetPassword(($_password))
$evryAdm.SetInfo()
$evryAdm.Description = "Evry service account, do not delete"
$evryAdm.UserFlags.Value = $evryAdm.UserFlags.Value -bor 0x10000 #Set "Account never expires" flag
$evryAdm.SetInfo()
$adsi.Children | where {$_.Name -eq "Administrators"} | foreach {$_.psbase.Invoke(“Add”,$evryAdm.path)}
Write-Host "Evryadm created successfully" -ForegroundColor Cyan
}
else
{
Write-Host "evryadm already exist" -ForegroundColor Red
}
$guest = $adsi.Children | where {$_.Name -eq "Guest"}
$administrator = $adsi.Children | where {$_.Name -eq "Administrator"}
if ($guest)
{
$guest.UserFlags.Value = $guest.UserFlags.Value -bor 0x2 #Set "Account is disabled" flag
$guest.psbase.Rename("Visitor")
$guest.SetInfo()
Write-Host "Guest account Disabled" -ForegroundColor Cyan
}
else
{
Write-Host "Guest account is not present in the system" -ForegroundColor Red
}
if ($administrator)
{
$ass = Add-Type -AssemblyName System.Web
$passadm = [System.Web.Security.Membership]::GeneratePassword(18,2)
$passadm = ConvertTo-SecureString $passadm -AsPlainText -Force
$_bSTR = [system.runtime.interopservices.marshal]::SecureStringToBSTR($passadm)
$_passadm = [system.runtime.interopservices.marshal]::PtrToStringAuto($_bSTR)
$administrator.SetPassword(($_passadm))
$administrator.SetInfo()
$administrator.UserFlags.Value = $administrator.UserFlags.Value -bor 0x2 #Set "Account is disabled" flag
$administrator.psbase.Rename("Chief")
$administrator.SetInfo()
Write-Host "Administrator account Disabled" -ForegroundColor Cyan
}
else
{
Write-Host "Administrator account is not present in the system" -ForegroundColor Red
}
#Read-Host -Prompt "Press any key to continue..."
}
function Set-LocalSecurytipolicy
{
$SecTemplate = @"
[Unicode]
Unicode=yes
[Version]
signature="`$CHICAGO`$"
Revision=1
[Privilege Rights]
SeInteractiveLogonRight = "Administrators"
SeRemoteInteractiveLogonRight = "Administrators","Remote Desktop Users"
"@
$SecTemplateFile = [System.IO.Path]::GetTempFileName()
Write-Host "Import new settings to Local Security Policy" -ForegroundColor DarkCyan
$SecTemplate | Set-Content -Path $SecTemplateFile -Encoding Unicode -Force
Push-Location (Split-Path $SecTemplateFile)
try {
secedit.exe /configure /db "secedit.sdb" /cfg "$($SecTemplateFile)"
} finally {
Pop-Location
}
Write-Host "LocalSecurytiPolicy set" -ForegroundColor Cyan
}
function Install-Sysmon
{
param ([Parameter(Mandatory=$true)] [String]$path)
$SysmonConfig = "Sysmon.exe"
$arg1 = "-accepteula"
$arg2 = "-i sysmon_conf.xml"
$scriptpath = Split-Path $path
$scriptpath = $scriptpath + "\sysmon"
Push-Location $scriptpath
[Environment]::CurrentDirectory = $PWD
try{
start-process $SysmonConfig -argumentlist $arg1,$arg2 -wait -Verb runAs
Write-Host "Sysmon installed" -ForegroundColor Cyan
}
catch{
Write-Host "Sysmon installaton failed" -ForegroundColor Red
}
finally{
Pop-Location
[Environment]::CurrentDirectory = $PWD
}
}
function Set-NTLM
{
$ntlm = Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" -Name UserAuthentication
if ($ntlm) {
$ntlm.UserAuthentication = 1
}
else
{
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" -Name UserAuthentication -PropertyType DWord -Value 1
}
}
function Set-Logsize{
$logList = @(Get-EventLog -list)
foreach ($logName in $logList)
{
if ($logName.logdisplayname -eq "System")
{
Select -ExpandProperty Maximumkilobytes
if ($LogSize -lt 40384)
{
limit-eventLog -logname System -MaximumSize 40384KB
}
}
elseif ($logName.logdisplayname -eq "Application")
{
Select -ExpandProperty Maximumkilobytes
if ($LogSize -lt 40384)
{
limit-eventLog -logname Application -MaximumSize 40384KB
}
}
elseif ($logName.logdisplayname -eq "Security")
{
Select -ExpandProperty Maximumkilobytes
if ($LogSize -lt 40384)
{
limit-eventLog -logname Security -MaximumSize 40384KB
}
}
}
}
function Delete-213.153.99Routes{
$regex = [regex] "\b213.153.99.\d{1,3}\b"
$ro = route print | findstr 213.153.99.
if ($ro){
$regex.Matches($ro) | % {Start-Process -FilePath route -ArgumentList "DELETE", $_.value -Verb RunAs
Write-Host $_.value" route deleted" -ForegroundColor Cyan}
}
else
{
Write-Host "No 213.153.99.xxx route found" -ForegroundColor Cyan
}
}
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{
#"No Administrative rights, it will display a popup window asking user for Admin rights"
$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments
break
}
$password = Read-Host -Prompt "Enter properly generated password for evryadm" -AsSecureString
Set-Admins $password
Set-LocalSecurytipolicy
Install-Sysmon $MyInvocation.MyCommand.Path
Set-NTLM
Set-Logsize
Delete-213.153.99Routes
# Synchronize system clocks for standalone (workgroup) hosts
if ((gwmi win32_computersystem).partofdomain -eq $false) {
Start-Process -FilePath w32tm -ArgumentList /config , /syncfromflags:manual, /manualpeerlist:213.153.104.1 -Wait -Verb RunAs
write-host -fore red "Ooops, workgroup!"
}
################################
##Old backup systems uninstall##
################################
Get-WmiObject -Class Win32_Service | where {$_.name -match "^TSM" -and $_.name -match "Acceptor$"} | % {$_.StopService()
$_.Delete()} | Out-Null
Get-WmiObject -Class Win32_Service | where {$_.name -match "^TSM" -and $_.name -match "Scheduler$"} | % {$_.StopService()
$_.delete()} | Out-Null
Get-WmiObject -Class Win32_Service | where {$_.name -match "^TSM" -and $_.name -match "Agent$"} | % {$_.StopService()
$_.delete()} | Out-Null
################### ENTER PROGRAMS NAMES TO UNINSTALL THEM. NOTE, THAT YOU SHOULD FOLLOW REGULAR EXPRESSION SYNTAX####
$uninstallPrograms = “(Tivoli Storage Manager|Data Protector|NetWorker)"
######################################################################################################################
$uninstallProgramsObj = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall |
Get-ItemProperty |
Where-Object {($_.DisplayName -MATCH $uninstallPrograms )}
Foreach ($obj in $uninstallProgramsObj)
{
if ($obj.UninstallString -match "MsiExec")
{
Write-Host "Uninstalling" $obj.displayname"..." -ForegroundColor Cyan
$obj.UninstallString -match "([{}][0-9A-Fa-f]{8}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{12}[}])" | Out-Null
& cmd /c msiexec.exe /x ''$Matches[1].ToString()'' /norestart /q
Write-Host "Uninstall complete" -ForegroundColor Cyan
}
else
{
Write-Host "Uninstall via MSIEXEC not supported, please uninstall "$obj.displayname" manually" -BackgroundColor Red
}
}
##################################
###NetBackup 7.6.1 installation###
##################################
$scriptpath = Split-Path $MyInvocation.MyCommand.Path
Switch ([intptr]::Size) {
4 {$scriptpath = $scriptpath + "\Netbackup86"}
8 {$scriptpath = $scriptpath + "\Netbackup64"}
}
Push-Location $scriptpath
[Environment]::CurrentDirectory = $PWD
try{
Start-Process silentclient_fqdn.cmd -Wait -NoNewWindow
}
finally{
Pop-Location
[Environment]::CurrentDirectory = $PWD
}
################################
#############VSSFIX#############
################################
#Erik Nordstrцm
#Eu9512
#root path for uninstall strings
$uninstallpath = "HKLM:\Software\Microsoft\Windows\CurrentVersion\uninstall"
#loop all items...
$items = Get-childItem $uninstallpath
foreach ($item in $items){$child = $item.PSChildName;
$path = "$uninstallpath\$child"
$Object = Get-ItemProperty $path -ErrorAction SilentlyContinue
#Uninstall VMware Tools VSS Provider if VMware
if ((Get-WmiObject Win32_Computersystem).Manufacturer -eq "VMware, Inc.")
{
if ($Object.DisplayName -eq "VMware Tools")
{
Write-Host "Uninstalling VMware Tools VSS Provider if found" -ForegroundColor Cyan
$UninstallGUID_VMware = $Object.PSchildName
cmd /c MsiExec.exe /i $UninstallGUID_VMware remove=VSS /passive /norestart
}
}}
Start-Sleep 2
# Install Symantec VSS provider for vSphere if VMware
if ((Get-WmiObject Win32_Computersystem).Manufacturer -eq "VMware, Inc.")
{
If ((Test-Path -Path ${env:ProgramFiles}'\VERITAS\NetBackup\bin\goodies\SYMCVSSProviderx86.msi') -eq $true)
{
Write-Host "Installing Symantec VSS Provider for vSphere" -ForegroundColor Cyan
& ${env:ProgramFiles}'\VERITAS\NetBackup\bin\goodies\SYMCVSSProviderx86.msi'
}
ElseIf ((Test-Path $env:ProgramFiles'\VERITAS\NetBackup\bin\goodies\SYMCVSSProviderx64.msi') -eq $true)
{
Write-Host "Installing Symantec VSS Provider" -ForegroundColor Cyan
& $env:ProgramFiles'\VERITAS\NetBackup\bin\goodies\SYMCVSSProviderx64.msi'
}
Else
{
Write-Host "Netbackup Client not found! Symantec VSS Provider will not be installed." -ForegroundColor Red
}
}
Write-Host "Installing task completed." -ForegroundColor Magenta
Start-Sleep 2
Read-Host