-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathApply-Hardening.psm1
93 lines (80 loc) · 2.67 KB
/
Apply-Hardening.psm1
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
function Apply-Hardening {
<#
.NOTES
===========================================================================
Created by: Markus Kraus
Twitter: @VMarkus_K
Private Blog: mycloudrevolution.com
===========================================================================
Changelog:
2016.11 ver 2.0 Base Release
===========================================================================
External Code Sources:
===========================================================================
Tested Against Environment:
vSphere Version: 5.5 U2
PowerCLI Version: PowerCLI 6.3 R1, PowerCLI 6.5 R1
PowerShell Version: 4.0, 5.0
OS Version: Windows 8.1, Server 2012 R2
Keyword: VM, Hardening, Security
===========================================================================
.DESCRIPTION
Applys a set of Hardening options to your VMs
.Example
Get-VM TST* | Apply-Hardening
.Example
$SampleVMs = Get-VM "TST*"
Apply-Hardening -VMs $SampleVMs
.PARAMETER VMs
Specify the VMs
#Requires PS -Version 4.0
#Requires -Modules VMware.VimAutomation.Core, @{ModuleName="VMware.VimAutomation.Core";ModuleVersion="6.3.0.0"}
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$true,
ValueFromPipeline=$True,
Position=0)]
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl[]]
$VMs
)
Process {
#region: Create Options
$ExtraOptions = @{
"isolation.tools.diskShrink.disable"="true";
"isolation.tools.diskWiper.disable"="true";
"isolation.tools.copy.disable"="true";
"isolation.tools.paste.disable"="true";
"isolation.tools.dnd.disable"="true";
"isolation.tools.setGUIOptions.enable"="false";
"log.keepOld"="10";
"log.rotateSize"="100000"
"RemoteDisplay.maxConnections"="2";
"RemoteDisplay.vnc.enabled"="false";
}
if ($DebugPreference -eq "Inquire") {
Write-Output "VM Hardening Options:"
$ExtraOptions | Format-Table -AutoSize
}
$VMConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
Foreach ($Option in $ExtraOptions.GetEnumerator()) {
$OptionValue = New-Object VMware.Vim.optionvalue
$OptionValue.Key = $Option.Key
$OptionValue.Value = $Option.Value
$VMConfigSpec.extraconfig += $OptionValue
}
#endregion
#region: Apply Options
ForEach ($VM in $VMs){
$VMv = Get-VM $VM | Get-View
$state = $VMv.Summary.Runtime.PowerState
Write-Output "...Starting Reconfiguring VM: $VM "
$TaskConf = ($VMv).ReconfigVM_Task($VMConfigSpec)
if ($state -eq "poweredOn") {
Write-Output "...Migrating VM: $VM "
$TaskMig = $VMv.MigrateVM_Task($null, $_.Runtime.Host, 'highPriority', $null)
}
}
}
#endregion
}