Skip to content

Commit

Permalink
Merge pull request microsoft#42 from Microsoft/anwather-master
Browse files Browse the repository at this point in the history
manual merge
  • Loading branch information
krjhitch authored Mar 28, 2017
2 parents 89aa2cd + 19e2aa1 commit 6e02b30
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DSCEA.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ PowerShellVersion = '5.0'
# NestedModules = @()

# Functions to export from this module
FunctionsToExport = ('Convert-DSCEAresultsToCSV','Get-DSCEAreport','Send-DSCEACSVtoSQL','Start-DSCEAscan')
FunctionsToExport = ('Convert-DSCEAresultsToCSV','Get-DSCEAreport','Send-DSCEACSVtoSQL','Start-DSCEAscan','Get-MOFRequiredModules','Copy-DSCResource')

# Cmdlets to export from this module
CmdletsToExport = '*'
Expand Down
82 changes: 82 additions & 0 deletions configs/SampleConfigWithExternalResource.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
configuration MemberServerSecuritySettings {
param([string[]]$ComputerName='localhost')

Import-DscResource -ModuleName PSDesiredStateConfiguration,xSMBShare

Node $ComputerName {

#Anti-Malware
Service 'MicrosoftAntimalwareService' {
Name = 'MsMpSvc'
StartupType = 'Automatic'
State = 'Running'
}

#User Account Control - (1 of 2)
Registry 'ConsentPromptBehaviorAdmin' {
Ensure = 'Present'
Key = 'HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System'
ValueName = 'ConsentPromptBehaviorAdmin'
ValueType = 'Dword'
ValueData = '5'
}

#User Account Control - (2 of 2)
Registry 'PromptOnSecureDesktop' {
Ensure = 'Present'
Key = 'HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System'
ValueName = 'PromptOnSecureDesktop'
ValueType = 'Dword'
ValueData = '1'
}

#Interactive logon: Number of previous logons to cache (in case domain controller is not available)
Registry 'Numberofpreviouslogonstocache' {
Ensure = 'Present'
Key = 'HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon'
ValueName = 'CachedLogonsCount'
ValueType = 'Dword'
ValueData = '2'
}

#Checks to ensure that certain Windows Roles or Windows Features have not been installed
WindowsFeature 'ActiveDirectoryDomainServices' {
Name = 'AD-Domain-Services'
Ensure = 'Absent'
}

#Ensure DNS service is not installed
WindowsFeature 'DNSServer' {
Name = 'DNS'
Ensure = 'Absent'
}

#Ensure DHCP service is not installed
WindowsFeature 'DHCPServer' {
Name = 'DHCP'
Ensure = 'Absent'
}

#Ensure FaxServer service is not installed
WindowsFeature 'WindowsRoleFax' {
Name = 'Fax'
Ensure = 'Absent'
}

#Create a temp folder to share
File TempFolder {
DestinationPath = "C:\Temp"
Type = "Directory"
Ensure = "Present"
}

#Create a shared folder
xSMBShare TempShare {
Ensure = "Present"
Path = "C:\Temp"
Name = "TempShare"
}
}
}

MemberServerSecuritySettings -OutputPath .\
68 changes: 68 additions & 0 deletions functions/Get-MOFRequiredModules.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
function Get-MOFRequiredModules {
[CmdletBinding()]
Param($mofFile)

$DSCResources = Get-DscResource
$DScModuleArray = @()
$ModulesToCopy = @()

foreach ($Resource in $DscResources)
{
if (!(($Resource.ModuleName -eq "PSDesiredStateConfiguration") -or ($Resource.ImplementedAs -eq 'Binary')))
{
if ($DScModuleArray -notcontains $Resource.ModuleName)
{
$DSCModuleArray += $Resource.ModuleName
}
}
}

#Scan the mof file for sections ModuleName
$requiredModulesinMof = @()
Switch -Regex (Get-Content $mofFile)
{
"ModuleName" {$requiredModulesInMof += $_.Split("`"")[1]}
#Default {Write-Output $_}
}

foreach ($requiredModule in $requiredModulesInMof)
{
if ($requiredModule -in $DSCModuleArray)
{
$ModulesToCopy += [pscustomobject]@{
ModuleName = $requiredModule
#ModulePath = $DSCResources | Where ModuleName -eq $requiredModule | Select -ExpandProperty ParentPath
}
}
}

return $ModulesToCopy

}

function Copy-DSCResource
{
[cmdletBinding()]
Param($PSSession,$ModulestoCopy)

foreach ($Module in $ModulestoCopy)
{
$Source = 'C:\Program Files\WindowsPowerShell\Modules\'+$Module.ModuleName
Write-Verbose "Module location: $Source"
$Destination = 'C:\Program Files\WindowsPowerShell\Modules\'
try
{
Write-Verbose "Copying"
Copy-Item -ToSession $PSSession -Path $Source -Destination $Destination -Recurse -Force -ErrorAction STOP -Verbose
Write-Verbose "Copied"
}
catch
{
Write-Output $Error[0].Exception
break
}
}

}


20 changes: 20 additions & 0 deletions functions/Start-DSCEAscan.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ param

#Begin DSCEA Engine
Write-Verbose "DSCEA Scan has started"

$runspacePool = [RunspaceFactory]::CreateRunspacePool(1, 10).Open() #Min Runspaces, Max Runspaces
$scriptBlock = {
param (
Expand All @@ -140,6 +141,8 @@ param

[switch]$Force,

$ModulesRequired,

[Microsoft.Management.Infrastructure.CimSession]$CimSession
)

Expand Down Expand Up @@ -175,10 +178,22 @@ param
Repair-DSCEngine -ComputerName $computer -ErrorAction SilentlyContinue
}
}
#Copy resources if required
if ($ModulesRequired -ne $null) {
if($CimSession) {
$session = New-PSSession -ComputerName $CimSession.ComputerName
}
else {
$session = New-PSSession -ComputerName $Computer
}
Copy-DSCResource -PSSession $session -ModulestoCopy $ModulesRequired
Remove-PSSession $session
}
if($PSBoundParameters.ContainsKey('CimSession')) {
$DSCJob = Test-DSCConfiguration -ReferenceConfiguration $mofFile -CimSession $CimSession -AsJob | Wait-Job -Timeout $JobTimeout
}
else {

$DSCJob = Test-DSCConfiguration -ReferenceConfiguration $mofFile -CimSession $computer -AsJob | Wait-Job -Timeout $JobTimeout
}
if (!$DSCJob) {
Expand Down Expand Up @@ -229,11 +244,13 @@ param

if($PSBoundParameters.ContainsKey('CimSession')) {
$MofFile = (Get-Item $MofFile).FullName
$ModulesRequired = Get-MOFRequiredModules -mofFile $MofFile
$CimSession | ForEach-Object {
$params = @{
CimSession = $_
MofFile = $MofFile
JobTimeout = $JobTimeout
ModulesRequired = $ModulesRequired
}
if($PSBoundParameters.ContainsKey('Force')) {
$params += @{Force = $true}
Expand All @@ -250,6 +267,7 @@ param

if($PSBoundParameters.ContainsKey('ComputerName')){
$MofFile = (Get-Item $MofFile).FullName
$ModulesRequired = Get-MOFRequiredModules -mofFile $MofFile
$firstrunlist = $ComputerName
$psresults = Invoke-Command -ComputerName $firstrunlist -ErrorAction SilentlyContinue -AsJob -ScriptBlock {
$PSVersionTable.PSVersion
Expand Down Expand Up @@ -286,6 +304,7 @@ param

if($PSBoundParameters.ContainsKey('ComputerFile')){
$MofFile = (Get-Item $MofFile).FullName
$ModulesRequired = Get-MOFRequiredModules -mofFile $MofFile
$firstrunlist = Get-Content $InputFile
$psresults = Invoke-Command -ComputerName $firstrunlist -ErrorAction SilentlyContinue -AsJob -ScriptBlock {
$PSVersionTable.PSVersion
Expand All @@ -306,6 +325,7 @@ param
Computer = $_
MofFile = $MofFile
JobTimeout = $JobTimeout
ModulesRequired = $ModulesRequired
}
if ($PSBoundParameters.ContainsKey('Force')) {
$params += @{Force = $true}
Expand Down

0 comments on commit 6e02b30

Please sign in to comment.