-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstall-DCGSPLAScript.ps1
More file actions
180 lines (153 loc) · 5.02 KB
/
Copy pathInstall-DCGSPLAScript.ps1
File metadata and controls
180 lines (153 loc) · 5.02 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
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
<# create SPLA script#>
#Requires -Version 5
#Requires -RunAsAdministrator
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)]
[string]$companyName,
[Parameter(Mandatory=$true)]
[string]$contactName,
[Parameter(Mandatory=$true)]
[string]$contactEmailAddress,
[Parameter()]
[int]$auditType,
[Parameter()]
[string]$adminAcctExclusions = "Administrator",
[Parameter()]
[string]$rdsGroup,
[Parameter()]
[string]$sslVpnGroup,
[Parameter()]
[string]$officeGroup,
[Parameter()]
[string]$blaskGuardGroup,
[Parameter()]
[string]$exchangePlusUsersCount,
[Parameter()]
[string]$insecureScriptSenderPassword
)
$rootDir = "C:\DCG\SPLA"
$logsDir = "logs"
$companyFile = "$rootDir\company.conf"
$scriptRunner = "$rootDir\Run-SPLAScript.ps1"
$splaXMLfile = "$rootDir\spla.xml"
$scriptSender = "scriptsender@dcgla.net"
$EncryptedPasswordFile = "$rootDir\$scriptSender.securestring"
#Install-PackageProvider -Name NuGet -Force
#Install-Module -Name Invoke-CommandAs -Force
New-Item -ItemType Directory "$rootDir\$logsDir" -Force
New-Item -ItemType File $companyFile, $scriptRunner,$splaXMLfile -Force
If ($auditType -eq 0) {
while ($auditType -lt 1) {
[int]$auditType = Read-Host -Prompt "Input audit type:
Audit types (line 2) explained. Use one number for every audit type (i.e. AD and Exchange will be 13):
1- AD
2- RDS
3- Exchange
4- SQL
5- Office
6- Blaskguard
7- SSL VPN
Input a number here"
}
}
If (($auditType -match 2) -and ([string]::IsNullOrWhiteSpace($rdsGroup))) {
$rdsGroup = Read-Host "Define the RDS Group"
}
If (($auditType -match 2) -and ([string]::IsNullOrWhiteSpace($rdsGroup))) {
$sslVpnGroup = Read-Host "Define the SSLVPN Group"
}
Add-Content $companyFile "$companyName
$auditType
$contactName
$contactEmailAddress
$adminAcctExclusions
$rdsGroup
$sslVpnGroup
$officeGroup
$blaskGuardGroup
$exchangePlusUsersCount"
If ([string]::IsNullOrWhiteSpace($insecureScriptSenderPassword)) {
Read-Host -Prompt "Input password for $scriptSender" -AsSecureString |
ConvertFrom-SecureString |
Out-File -FilePath $EncryptedPasswordFile
}
Else {
$insecureScriptSenderPassword |
ConvertTo-SecureString -Force |
Out-File -FilePath $EncryptedPasswordFile
}
Add-Content $scriptRunner '[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$ScriptFromGitHub = Invoke-WebRequest https://raw.githubusercontent.com/path/to/SPLA/SPLAScriptv1.ps1
Invoke-Expression $($ScriptFromGitHub.Content)'
Add-Content $splaXMLfile '<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2019-02-28T14:11:18</Date>
<Author>dbreeden</Author>
<URI>\Run SPLA</URI>
</RegistrationInfo>
<Triggers>
<CalendarTrigger>
<StartBoundary>2019-02-28T08:00:00</StartBoundary>
<Enabled>true</Enabled>
<ScheduleByMonth>
<DaysOfMonth>
<Day>5</Day>
</DaysOfMonth>
<Months>
<January />
<February />
<March />
<April />
<May />
<June />
<July />
<August />
<September />
<October />
<November />
<December />
</Months>
</ScheduleByMonth>
</CalendarTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>S-1-5-21-1616510491-1821078637-2087108206-1156</UserId>
<LogonType>Password</LogonType>
<RunLevel>LeastPrivilege</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>true</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>powershell.exe</Command>
<Arguments>-WindowStyle Hidden -NonInteractive -Executionpolicy unrestricted -file C:\dcg\SPLA\Run-SPLAScript.ps1</Arguments>
<WorkingDirectory>c:\dcg\spla</WorkingDirectory>
</Exec>
</Actions>
</Task>'
$adminPassword = $password = Read-Host -Prompt "Enter the local admin password" -AsSecureString
$UserName = $env:username
$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $UserName, $adminPassword
$Password = $Credentials.GetNetworkCredential().Password
Register-ScheduledTask -Xml (get-content $splaXMLfile | out-string) -TaskName "Run SPLA" -User $UserName -Password $password -Force