Skip to content

Commit

Permalink
functions to copy determine and copy modules
Browse files Browse the repository at this point in the history
  • Loading branch information
anwather committed Mar 24, 2017
1 parent 1cbd679 commit 698a4f2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 70 deletions.
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
19 changes: 16 additions & 3 deletions functions/Get-MOFRequiredModules.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,26 @@
function Copy-DSCResource
{
[cmdletBinding()]
Param($CimSession,$ModulestoCopy)
Param($PSSession,$ModulestoCopy)

foreach ($Module in $ModulestoCopy)
{
$Source = 'C:\Program Files\WindowsPowerShell\Modules'+$Module.ModuleName
Write-Verbose $Source
$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
}
}

}


66 changes: 0 additions & 66 deletions functions/HelperModule/Get-MOFRequiredModules.psm1

This file was deleted.

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

#Begin DSCEA Engine
Write-Verbose "DSCEA Scan has started"
#Scan the Mof file for modules other than built in
$MofFile = (Get-Item $MofFile).FullName
$ModulesRequired = Get-MOFRequiredModules -mofFile $MofFile

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

[switch]$Force,

$ModulesRequired,

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

Expand Down Expand Up @@ -172,10 +177,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 @@ -209,6 +226,7 @@ param
CimSession = $_
MofFile = $MofFile
JobTimeout = $JobTimeout
ModulesRequired = $ModulesRequired
}
if($PSBoundParameters.ContainsKey('Force')) {
$params += @{Force = $true}
Expand Down Expand Up @@ -251,6 +269,7 @@ param
Computer = $_
MofFile = $MofFile
JobTimeout = $JobTimeout
ModulesRequired = $ModulesRequired
}
if ($PSBoundParameters.ContainsKey('Force')) {
$params += @{Force = $true}
Expand Down

0 comments on commit 698a4f2

Please sign in to comment.