Script resources.

Welcome Forums General PowerShell Q&A Script resources.

This topic contains 1 reply, has 2 voices, and was last updated by

 
Keymaster
1 year, 5 months ago.

  • Author
    Posts
  • #71549

    Participant
    Points: 21
    Rank: Member

    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
  • #71557

    Keymaster
    Points: 1,644
    Helping HandTeam Member
    Rank: Community Hero

    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.

The topic ‘Script resources.’ is closed to new replies.