Modules/DscOperations/DscOperations.psm1

#Region './prefix.ps1' 0
Set-StrictMode -Version latest
$ErrorActionPreference = 'Stop'

Import-Module $PSScriptRoot/../GuestConfigPath -Force
#EndRegion './prefix.ps1' 5
#Region './Public/Get-DscConfiguration.ps1' 0
<#
    .SYNOPSIS
        Get DSC configuration.

    .Parameter ConfigurationName
        Configuration name.

    .Example
        Get-DscConfiguration -ConfigurationName WindowsTLS
#>


function Get-DscConfiguration
{
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [System.String]
        $ConfigurationName
    )

    Remove-Item (Get-GuestConfigLogPath) -ErrorAction SilentlyContinue -Force
    Remove-Item (Get-GuestConfigAssignmentReportFolderPath -ConfigurationName $ConfigurationName) -ErrorAction SilentlyContinue -Force -Recurse

    $gcWorkerPath = Get-GuestConfigWorkerBinaryPath
    Start-Process $gcWorkerPath -ArgumentList  "-o run_consistency -a $ConfigurationName -r -c Pending" -Wait -NoNewWindow
    Start-Sleep -Seconds 1
    Write-GCOperationConsoleMessages -Verbose:($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent)

    $reportPath = Get-GuestConfigAssignmentReportFilePath -ConfigurationName $ConfigurationName
    return ConvertFrom-Json (Get-Content $reportPath -Raw)
}
#EndRegion './Public/Get-DscConfiguration.ps1' 34
#Region './Public/Publish-DscConfiguration.ps1' 0
<#
    .SYNOPSIS
        Publish DSC configuration.

    .Parameter ConfigurationName
        Configuration name.

    .Parameter Path
        Policy Path.

    .Example
        Publish-DscConfiguration -Path C:\metaconfig
#>


function Publish-DscConfiguration
{
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [string]
        $ConfigurationName,

        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [string]
        $Path
    )
    if (-not (Test-Path -Path $Path))
    {
        throw "Guest Config DSC Config not found at path $testPath"
    }

    Remove-Item (Get-GuestConfigLogPath) -ErrorAction SilentlyContinue -Force

    $gcWorkerPath = Get-GuestConfigWorkerBinaryPath
    Start-Process $gcWorkerPath -ArgumentList  "-o publish_assignment -a $ConfigurationName -p $Path" -Wait -NoNewWindow
    Start-Sleep -Seconds 1
    Write-GCOperationConsoleMessages -Verbose:($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent)
}
#EndRegion './Public/Publish-DscConfiguration.ps1' 42
#Region './Public/Set-DscLocalConfigurationManager.ps1' 0
<#
    .SYNOPSIS
        Set DSC LCM settings.

    .Parameter ConfigurationName
        Configuration name.

    .Example
        Set-DscLocalConfigurationManager -Path C:\metaconfig
#>


function Set-DscLocalConfigurationManager
{
    [CmdletBinding()]
    param
    (
        [Parameter(Position=0, Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [string]
        $ConfigurationName,

        [Parameter(Position=1, Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [string]
        $Path
    )

    Remove-Item (Get-GuestConfigLogPath) -ErrorAction SilentlyContinue -Force

    $gcWorkerPath = Get-GuestConfigWorkerBinaryPath
    Start-Process $gcWorkerPath -ArgumentList  "-o set_agent_settings -a $ConfigurationName -p $Path" -Wait -NoNewWindow
    Start-Sleep -Seconds 1
    Write-GCOperationConsoleMessages -Verbose:($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent)
}
#EndRegion './Public/Set-DscLocalConfigurationManager.ps1' 35
#Region './Public/Start-DscConfiguration.ps1' 0
<#
    .SYNOPSIS
        Start DSC configuration.

    .Parameter ConfigurationName
        Configuration name.

    .Example
        Start-DscConfiguration -ConfigurationName WindowsTLS
#>

function Start-DscConfiguration
{
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [System.String]
        $ConfigurationName
    )

    Remove-Item (Get-GuestConfigLogPath) -ErrorAction SilentlyContinue -Force
    Remove-Item (Get-GuestConfigAssignmentReportFolderPath -ConfigurationName $ConfigurationName) -ErrorAction SilentlyContinue -Force -Recurse

    $gcWorkerPath = Get-GuestConfigWorkerBinaryPath
    Start-Process $gcWorkerPath -ArgumentList  "-o run_consistency -a $ConfigurationName -r -s inguest_apply_and_monitor -c Pending" -Wait -NoNewWindow
    Start-Sleep -Seconds 1
    Write-GCOperationConsoleMessages -Verbose:($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent)
}
#EndRegion './Public/Start-DscConfiguration.ps1' 29