Author Posts

May 26, 2017 at 4:05 pm

Got some time to play around with dsc again. I've written a simple script, or so I thought. It won't apply to the machine and the get/set/test don't show up int get-dscconfiguration

ConfigurationName : Basebuild
DependsOn :
ModuleName : PSDesiredStateConfiguration
ModuleVersion : 1.1
PsDscRunAsCredential :
ResourceId : [Script]DisableRouterDiscovery
SourceInfo :
Credential :
GetScript :
Result : Disabled
SetScript :
TestScript :
PSComputerName :
CimClassName : MSFT_ScriptResource

Configuration Basebuild {

    param(
        [string[]]$ComputerName="localhost"
    )


Import-DscResource –ModuleName 'PSDesiredStateConfiguration'


    Node $ComputerName {

        Script DisableRouterDiscovery           
        {            
            # Must return a hashtable with at least one key            
            # named 'Result' of type String            
            GetScript = {            
                Return @{            
                    Result = [string]$((Get-NetIPInterface e* -AddressFamily Ipv6).routerdiscovery)            
                }            
            }            
            
            # Must return a boolean: $true or $false            
            TestScript = {            
                If (((Get-NetIPInterface e* -AddressFamily Ipv6).routerdiscovery) -contains 'Enabled') {            
                    Write-Verbose "Routerdiscovery enabled for one or more interfaces"            
                    Return $false            
                } Else {            
                    Write-Verbose "Routerdiscovery disabled for all interfaces"            
                    Return $true            
                }            
            }            
            
            # Returns nothing            
            SetScript = {            
                Write-Verbose "Disabling router discovery for all interfaces"            
                Get-NetIPInterface -AddressFamily IPv6 -InterfaceAlias e* | Set-NetIPInterface -RouterDiscovery disabled            
            }            
        }      


    }

}

Basebuild -computername mycomputer

May 26, 2017 at 4:13 pm

You're going to have to probably enable a DSCTrace on the Node where you're applying this, run a consistency check, and then see what winds up in the DSC event log.

I'm not sure what "won't apply to the machine" means – does that mean, it's "applying" but "not having any effect?" I'd have to look and see what the Test was doing, to see if the LCM even thought the Set should run or not. And then obviously if Test was working, see if the Set was chucking an error or something.