-
Notifications
You must be signed in to change notification settings - Fork 0
/
Server2012R2_PowerSTIGlab_PostConfigure.ps1
59 lines (47 loc) · 1.96 KB
/
Server2012R2_PowerSTIGlab_PostConfigure.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
#get current PowerSTIG version path
$currentModuleVersion = (Get-ChildItem -Path 'C:\Program Files\WindowsPowerShell\Modules\PowerSTIG').Name
$currentModulePath = "C:\Program Files\WindowsPowerShell\Modules\PowerSTIG\" + $currentModuleVersion.Trim("'")+"\"
#clones your branch to this VM
git clone -b "YOUBRANCHHERE" https://github.com/Microsoft/PowerStig.git c:\Github -q
#get modules required by your branch and updates modules locally
$ModulesTest = Get-Content C:\Github\PowerStig.psd1 | Select-String -Pattern "ModuleName = '(.*)'; ModuleVersion = '(.*)'" | % {"Install-Module $($_.matches.groups[1]) -RequiredVersion $($_.matches.groups[2]) -force"} >> C:\Modules.ps1
C:\Modules.ps1
#copy required files from your branch to PowerSTIG module directory
$itemsToCopy = "PowerStig.psd1", "PowerStig.psm1"
foreach($item in $itemsToCopy)
{
$path = "C:\Github\" + $item
$destination = $currentModulePath + $item
Copy-Item -Path $path -Destination $destination -force -Recurse
}
$dirToCopy = "DSCResources", "Module", "StigData\Processed"
foreach($dir in $dirToCopy)
{
$path = "C:\Github\" + $dir
$destination = $currentModulePath
Copy-Item -Path $path -Destination $destination -force -Recurse
}
#update PowerSTIG version if newer than current release
$powerstigVersion = Get-Content C:\Github\PowerStig.psd1 | Select-String -Pattern "ModuleVersion = (.*)"
$version = $powerstigVersion.matches.groups[1].Value
Rename-Item -Path $currentModulePath -newName $version.trim("'") -verbose
#update MaxEnvelope Size
Set-Item -Path WSMan:\localhost\MaxEnvelopeSizekb -Value 8192
#Create test database
Configuration Example
{
Import-DscResource -ModuleName SqlServerDsc
$hostname = hostname
node localhost
{
SqlDatabase Create_Database
{
Ensure = 'Present'
ServerName = $hostname
InstanceName = 'MSSQLSERVER'
Name = 'TestDatabase'
}
}
}
Example
Start-DscConfiguration .\Example -wait -verbose -force