Downloads:

19,323

Downloads of v 2.0.0-alpha9:

270

Last Update:

30 Jul 2015

Package Maintainer(s):

Software Author(s):

  • SEEK Ltd.

Tags:

admin DSC

SEEK DSC Networking

This is a prerelease version of SEEK DSC Networking.

2.0.0-alpha9 | Updated: 30 Jul 2015

Downloads:

19,323

Downloads of v 2.0.0-alpha9:

270

Software Author(s):

  • SEEK Ltd.

Tags:

admin DSC

SEEK DSC Networking 2.0.0-alpha9

This is a prerelease version of SEEK DSC Networking.

All Checks are Unknown

2 Test of Unknown Status


Validation Testing Unknown


Verification Testing Unknown

To install SEEK DSC Networking, run the following command from the command line or from PowerShell:

>

To upgrade SEEK DSC Networking, run the following command from the command line or from PowerShell:

>

To uninstall SEEK DSC Networking, run the following command from the command line or from PowerShell:

>

NOTE: This applies to both open source and commercial editions of Chocolatey.

1. Ensure you are set for organizational deployment

Please see the organizational deployment guide

  • Open Source or Commercial:
    • Proxy Repository - Create a proxy nuget repository on Nexus, Artifactory Pro, or a proxy Chocolatey repository on ProGet. Point your upstream to https://chocolatey.org/api/v2. Packages cache on first access automatically. Make sure your choco clients are using your proxy repository as a source and NOT the default community repository. See source command for more information.
    • You can also just download the package and push it to a repository Download

3. Enter your internal repository url

(this should look similar to https://chocolatey.org/api/v2)

4. Choose your deployment method:


choco upgrade seek-dsc-networking -y --source="'STEP 3 URL'" [other options]

See options you can pass to upgrade.

See best practices for scripting.

Add this to a PowerShell script or use a Batch script with tools and in places where you are calling directly to Chocolatey. If you are integrating, keep in mind enhanced exit codes.

If you do use a PowerShell script, use the following to ensure bad exit codes are shown as failures:


choco upgrade seek-dsc-networking -y --source="'STEP 3 URL'" 
$exitCode = $LASTEXITCODE

Write-Verbose "Exit code was $exitCode"
$validExitCodes = @(0, 1605, 1614, 1641, 3010)
if ($validExitCodes -contains $exitCode) {
  Exit 0
}

Exit $exitCode

- name: Ensure seek-dsc-networking installed
  win_chocolatey:
    name: seek-dsc-networking
    state: present
    version: 2.0.0-alpha9
    source: STEP 3 URL

See docs at https://docs.ansible.com/ansible/latest/modules/win_chocolatey_module.html.

Coming early 2020! Central Managment Reporting available now! More information...


chocolatey_package 'seek-dsc-networking' do
  action    :install
  version  '2.0.0-alpha9'
  source   'STEP 3 URL'
end

See docs at https://docs.chef.io/resource_chocolatey_package.html.


Chocolatey::Ensure-Package
(
    Name: seek-dsc-networking,
    Version: 2.0.0-alpha9,
    Source: STEP 3 URL
);

Requires Otter Chocolatey Extension. See docs at https://inedo.com/den/otter/chocolatey.


cChocoPackageInstaller seek-dsc-networking
{
   Name     = 'seek-dsc-networking'
   Ensure   = 'Present'
   Version  = '2.0.0-alpha9'
   Source   = 'STEP 3 URL'
}

Requires cChoco DSC Resource. See docs at https://github.com/chocolatey/cChoco.


package { 'seek-dsc-networking':
  provider => 'chocolatey',
  ensure   => '2.0.0-alpha9',
  source   => 'STEP 3 URL',
}

Requires Puppet Chocolatey Provider module. See docs at https://forge.puppet.com/puppetlabs/chocolatey.


salt '*' chocolatey.install seek-dsc-networking version="2.0.0-alpha9" source="STEP 3 URL"

See docs at https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.chocolatey.html.

5. If applicable - Chocolatey configuration/installation

See infrastructure management matrix for Chocolatey configuration elements and examples.

This package was approved as a trusted package on 30 Jul 2015.

Description

Custom DSC Resources for networking administration


lib\cNetworking\cNetworking.psd1
 
lib\cNetworking\DSCResources\SEEK_cCertReq\SEEK_cCertReq.psm1
<# NOTE: This SSL certificate request module is designed for Local Dev machines ONLY !!! #>

<#
Retrieves a SSL certificate for a Subject located on machine
#>

function Get-TargetResource
{
    [CmdletBinding()]
    [OutputType([System.Collections.Hashtable])]
    param
    (
        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [String]$Subject,

        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [String]$CertPath
    )

    Write-Verbose "Getting CERT"

    $theCert = Get-ChildItem -path $CertPath | Where-Object {$_.Subject -eq $Subject}

    #find the certificate and return
    $certResult = @{
        Subject = $Cert.Subject
        Ensure = "Present"
        SANs = $Cert.DnsNameList
        OnlineCA = $Cert.Issuer
    }

    return $certResult
}

<#
Creates a SSL certificate for a Subject on machine if Present is ensured.
Removes SSL certificate for a Subject on machine if Absent is ensured.
#>
function Set-TargetResource
{
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [String]$Subject,

        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [String]$CertPath,

        [ValidateSet("Present", "Absent")]
        [string]$Ensure = "Present",

        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [String[]]$SANs,

        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [String]$OnlineCA
    )

    Write-Verbose "Setting CERT"

    if($Ensure -eq "Present")
    {
        Write-Verbose "Creating CERT for $Subject"

        #call certreq
        $subjectDomain = $Subject.split(',')[0].split('=')[1]
        if ($subjectDomain -match "\*.") {
            $subjectDomain = $subjectDomain -replace "\*", "star"
        }
        $CertificateINI = "$subjectDomain.ini"
        $CertificateREQ = "$subjectDomain.req"
        $CertificateRSP = "$subjectDomain.rsp"
        $CertificateCER = "$subjectDomain.cer"

        ### INI file generation
        new-item -type file $CertificateINI -force
        add-content $CertificateINI '[Version]'
        add-content $CertificateINI 'Signature="$Windows NT$"'
        add-content $CertificateINI ''
        add-content $CertificateINI '[NewRequest]'
        $temp = 'Subject="' + $Subject + '"'
        add-content $CertificateINI $temp
        add-content $CertificateINI 'Exportable=TRUE'
        add-content $CertificateINI 'KeyLength=2048'
        add-content $CertificateINI 'KeySpec=1'
        add-content $CertificateINI 'KeyUsage=0xA0'
        add-content $CertificateINI 'MachineKeySet=True'
        add-content $CertificateINI 'ProviderName="Microsoft RSA SChannel Cryptographic Provider"'
        add-content $CertificateINI 'ProviderType=12'
        add-content $CertificateINI 'RequestType=CMC'
        add-content $CertificateINI ''
        add-content $CertificateINI '[RequestAttributes]'
        add-content $CertificateINI 'CertificateTemplate="WebServer"'
        add-content $CertificateINI ''
        add-content $CertificateINI '[EnhancedKeyUsageExtension]'
        add-content $CertificateINI 'OID=1.3.6.1.5.5.7.3.1'
        add-content $CertificateINI ''

        if ($SANs) {
            add-content $CertificateINI '[Extensions]'
            add-content $CertificateINI '2.5.29.17 = "{text}"'

            foreach ($SAN in $SANs) {
                $temp = '_continue_ = "dns=' + $SAN + '&"'
                add-content $CertificateINI $temp
            }
        }

        try
        {
            ### Certificate request generation
            if (test-path $CertificateREQ)     {
                del $CertificateREQ
            }

            Write-Verbose "Converting $CertificateINI to CSR: certreq -new $CertificateINI $CertificateREQ"
            certreq -new $CertificateINI $CertificateREQ

            ### Online certificate request and import
            if ($OnlineCA) {
                if (test-path $CertificateCER) {del $CertificateCER}
                if (test-path $CertificateRSP) {del $CertificateRSP}

                Write-Verbose "Submitting: certreq -submit -config $OnlineCA $CertificateREQ $CertificateCER"
                certreq -submit -config $OnlineCA $CertificateREQ $CertificateCER


                Write-Verbose "Merging certificate response file and CSR together to generate SSL certificate: certreq -accept -config $OnlineCA $CertificateCER"
                certreq -accept -config $OnlineCA $CertificateCER
            }

            Write-Verbose "Finished creating CERT for $Subject"
        }
        catch
        {
            $errorId = "CertReqFailure";
            $errorCategory = [System.Management.Automation.ErrorCategory]::InvalidOperation;
            $errorMessage = "CertGenerationFailure -f ${Name}";
            $exception = New-Object System.InvalidOperationException $errorMessage ;
            $errorRecord = New-Object System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $null

            $PSCmdlet.ThrowTerminatingError($errorRecord)
        }

        Test-TargetResource $Subject $CertPath $Ensure $SANs $OnlineCA
    }
    else
    {
        Write-Verbose "Removing CERT for $Subject"
        $theCert = Get-ChildItem -path $CertPath | Where-Object {$_.Subject -eq $Subject}

        if ($theCert -ne $null)
        {
            $Thumbprint = $theCert.Thumbprint
            Remove-Item -Path "$CertPath\$Thumbprint"

            Write-Verbose "Successfully removed CERT for $Subject"
        }
    }
}

<#
Tests a SSL certificate for a Subject IS located on machine if Present is ensured.
Tests a SSL certificate for a Subject IS NOT located on machine if Absent is ensured.
#>
function Test-TargetResource
{
    [CmdletBinding()]
    [OutputType([System.Boolean])]
    param
    (
        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [String]$Subject,

        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [String]$CertPath,

        [ValidateSet("Present", "Absent")]
        [string]$Ensure = "Present",

        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [String[]]$SANs,

        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [String]$OnlineCA
    )

    Write-Verbose "Testing CERT"
    #test that the cert is there
    $theCert = Get-ChildItem -path $CertPath | Where-Object {$_.Subject -eq $Subject}

    if ($theCert -ne $null -and $Ensure -eq "Present")
    {
        Write-Verbose "CERT Thumbprint is $theCert"
        Write-Verbose "CERT is expected to be Present and is Present"
        return $true
    }

    if ($theCert -eq $null -and $Ensure -eq "Absent")
    {
        Write-Verbose "CERT is expected to be Absent and is Absent"
        return $true
    }

    return $false
}


#  FUNCTIONS TO BE EXPORTED
Export-ModuleMember -function Get-TargetResource, Set-TargetResource, Test-TargetResource
lib\cNetworking\DSCResources\SEEK_cCertReq\SEEK_cCertReq.schema.mof
 
lib\cNetworking\DSCResources\SEEK_cFirewallRule\SEEK_cFirewallRule.psm1
function Get-TargetResource
{
    [CmdletBinding()]
    [OutputType([System.Collections.Hashtable])]
    param
    (
        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [System.String]$Name
    )


    try
    {
        $advFirewallOutput = (Invoke-NetshAdvFirewall -Name $Name -Operation "show")
        $firewallRuleExists = $advFirewallOutput -match "Rule Name:\s+$Name\s+"
    }
    catch
    {
        $firewallRuleExists = $false
    }

    if (-not $firewallRuleExists)
    {
        return @{
            Name = $Name
            Direction = $null
            LocalPort = $null
            Protocol = $null
            Action = $null
            Ensure = "Absent"
        }
    }

    if ($advFirewallOutput -match "Direction:\s+(.+?)\s+")
    {
        $direction = switch ($Matches[1])
        {
            "in" {"Inbound"}
            "out" {"Outbound"}
        }
    }
    if ($advFirewallOutput -match "LocalPort:\s+(.+?)\s+")
    {
        $localport = $Matches[1]
    }
    if ($advFirewallOutput -match "Protocol:\s+(.+?)\s+")
    {
        $protocol = $Matches[1]
    }
    if ($advFirewallOutput -match "Action:\s+(.+?)\s+")
    {
        $action = $Matches[1]
    }

    return @{
        Name = $Name
        Direction = $direction
        LocalPort = $localPort
        Protocol = $protocol
        Action = $action
        Ensure = "Present"
    }
}

function Set-TargetResource
{
    [CmdletBinding(DefaultParameterSetName = "Absent")]
    param
    (
        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [System.String]$Name,

        [parameter(Mandatory=$true,ParameterSetName = "Present")]
        [ValidateSet("Inbound","Outbound")]
        [System.String]$Direction,

        [parameter(Mandatory=$true,ParameterSetName = "Present")]
        [ValidateNotNullOrEmpty()]
        [System.String]$LocalPort,

        [parameter(Mandatory=$true,ParameterSetName = "Present")]
        [ValidateSet("TCP","UDP")]
        [System.String]$Protocol,

        [parameter(Mandatory=$true,ParameterSetName = "Present")]
        [ValidateSet("Allow","Block", "Bypass")]
        [System.String]$Action,

        [parameter(Mandatory=$false,ParameterSetName = "Present")]
        [parameter(Mandatory=$true,ParameterSetName = "Absent")]
        [ValidateSet("Present","Absent")]
        [System.String]
        $Ensure  = "Present"
    )

    if ($Ensure -eq "Present")
    {
        New-NetFirewallRule -Name $Name `
            -Direction $Direction `
            -LocalPort $LocalPort `
            -Protocol $Protocol `
            -Action $Action
    }
    else
    {
        Remove-NetFirewallRule -Name $Name
    }
}

function Test-TargetResource
{
    [CmdletBinding(DefaultParameterSetName = "Absent")]
    param
    (
        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [System.String]$Name,

        [parameter(Mandatory=$true,ParameterSetName = "Present")]
        [ValidateSet("Inbound","Outbound")]
        [System.String]$Direction,

        [parameter(Mandatory=$true,ParameterSetName = "Present")]
        [ValidateNotNullOrEmpty()]
        [System.String]$LocalPort,

        [parameter(Mandatory=$true,ParameterSetName = "Present")]
        [ValidateSet("TCP","UDP")]
        [System.String]$Protocol,

        [parameter(Mandatory=$true,ParameterSetName = "Present")]
        [ValidateSet("Allow","Block", "Bypass")]
        [System.String]$Action,

        [parameter(Mandatory=$false,ParameterSetName = "Present")]
        [parameter(Mandatory=$true,ParameterSetName = "Absent")]
        [ValidateSet("Present","Absent")]
        [System.String]
        $Ensure  = "Present"
    )

    $firewallRule = Get-TargetResource -Name $Name

    if ($Ensure -eq "Absent" -and $firewallRule.Ensure -eq "Absent")
    {
        return $true
    }

    if ($Ensure -eq "Present" `
        -and $firewallRule.Ensure -eq "Present" `
        -and $firewallRule.Direction -eq $Direction `
        -and $firewallRule.LocalPort -eq $LocalPort `
        -and $firewallRule.Protocol -eq $Protocol `
        -and $firewallRule.Action -eq $Action)
    {
        return $true
    }

    return $false
}

function New-NetFirewallRule
{
    param
    (
        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]$Name,

        [String]$Protocol,

        [String]$LocalPort,

        [ValidateSet("Inbound", "Outbound")]
        [String]$Direction,

        [ValidateSet("Allow", "Block", "Bypass")]
        [String]$Action
    )

    Invoke-NetshAdvFirewall -Name $Name `
        -Operation "add" `
        -Protocol $Protocol `
        -LocalPort $LocalPort `
        -Direction $Direction `
        -Action $Action
}

function Remove-NetFirewallRule
{
    param
    (
        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]$Name
    )

    Invoke-NetshAdvFirewall -Name $Name -Operation "del"
}

function Invoke-NetshAdvFirewall
{
    [CmdletBinding()]
    [OutputType([System.String])]
    param
    (
        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]$Name,

        [parameter(Mandatory = $true)]
        [ValidateSet("add","del","show")]
        [String]$Operation,

        [String]$Protocol,

        [String]$LocalPort,

        [ValidateSet("Inbound", "Outbound")]
        [String]$Direction,

        [ValidateSet("Allow", "Block", "Bypass")]
        [String]$Action
    )

    $argumentList = @(
        'advfirewall', 'firewall', $Operation, 'rule',
        "name=""${Name}"""
    )

    if ($Direction)
    {
        $dir = switch ($Direction)
        {
            "Inbound" {"in"}
            "Outbound" {"out"}
        }
        $argumentList += "dir=$dir"
    }

    if ($Protocol)
    {
        $argumentList += "protocol=$Protocol"
    }

    if ($LocalPort)
    {
        $argumentList += "localport=$LocalPort"
    }

    if ($Action)
    {
        $argumentList += "action=$Action"
    }

    $outputPath = "${env:TEMP}\netsh.out"
    $process = Start-Process netsh -ArgumentList $argumentList -Wait -NoNewWindow -RedirectStandardOutput $outputPath -Passthru
    if ($process.ExitCode -ne 0) { throw "Error performing operation '$Operation' for firewall rule"}
    return ((Get-Content $outputPath) -join "`n")
}

Export-ModuleMember -function Get-TargetResource, Set-TargetResource, Test-TargetResource
lib\cNetworking\DSCResources\SEEK_cFirewallRule\SEEK_cFirewallRule.schema.mof
 
lib\cNetworking\DSCResources\SEEK_cIPAddress\SEEK_cIPAddress.psm1
<#######################################################################################
 #  MSDSCPack_IPAddress : DSC Resource that will set/test/get the current IP
 #  Address, by accepting values among those given in MSDSCPack_IPAddress.schema.mof
 #######################################################################################>



######################################################################################
# The Get-TargetResource cmdlet.
# This function will get the present list of IP Address DSC Resource schema variables on the system
######################################################################################
function Get-TargetResource
{
    param
    (
        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [String]$IPAddress,

        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [String]$NodeName
    )

    Write-Warning "SEEK_cIPAddress resource is obsolete, please use SEEK_cStaticIpAddress"

    $returnValue = @{
    }

    $returnValue
}

######################################################################################
# The Set-TargetResource cmdlet.
# This function will set a new IP Address in the current node
######################################################################################
function Set-TargetResource
{
    param
    (
        #IP Address that has to be set
        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [String]$IPAddress,

        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [String]$NodeName
    )

    Write-Warning "SEEK_cIPAddress resource is obsolete, please use SEEK_cStaticIpAddress"

    ValidateProperties @PSBoundParameters
}

######################################################################################
# The Test-TargetResource cmdlet.
# This will test if the given IP Address is among the current node's IP Address collection
######################################################################################
function Test-TargetResource
{
    param
    (
        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [String]$IPAddress,

        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [String]$NodeName
    )

    Write-Warning "SEEK_cIPAddress resource is obsolete, please use SEEK_cStaticIpAddress"

    $result = ValidateProperties @PSBoundParameters

    if ($result -eq $false)
    {
        $errorId = "WebsiteBindingConflictOnStart";
        $errorCategory = [System.Management.Automation.ErrorCategory]::InvalidResult
        $errorMessage = "IPAddress $IPAddress not found..."
        $exception = New-Object System.InvalidOperationException $errorMessage
        $errorRecord = New-Object System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $null

        $PSCmdlet.ThrowTerminatingError($errorRecord);
    }

    $result
}


#######################################################################################
#  Helper function that validates the IP Address properties. If the switch parameter
# "Apply" is set, then it will set the properties after a test
#######################################################################################
function ValidateProperties
{
    param
    (
        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [String]$IPAddress,

        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [String]$NodeName,

        [Switch]$Apply
    )

    $ip = $IPAddress

    if(!([System.Net.Ipaddress]::TryParse($ip, [ref]0)))
    {
       throw "IP Address *$IPAddress* is not in the correct format. Please correct the ipaddress in the configuration and try again"
    }
    try
    {
        #Write-Verbose -Message "Checking the IPAddress ..."
        $Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $NodeName | ? {$_.IPEnabled}

        foreach($Network in $Networks)
        {
            if ($Network.IPAddress.Contains($IPAddress))
            {
                return $true
                break;
            }
        }
        Write-Verbose -Message "IPAddressFound $IPAddressFound"
        return $false
    }
    catch
    {
       Write-Verbose -Message $_
       throw "Can not set or find valid IPAddress using InterfaceAlias $InterfaceAlias and AddressFamily $AddressFamily"
    }
}



#  FUNCTIONS TO BE EXPORTED
Export-ModuleMember -function Get-TargetResource, Set-TargetResource, Test-TargetResource
lib\cNetworking\DSCResources\SEEK_cIPAddress\SEEK_cIPAddress.schema.mof
 
lib\cNetworking\DSCResources\SEEK_cStaticIpAddress\SEEK_cStaticIpAddress.psm1
# NOTE: Supports IPv4 addresses only

function Get-TargetResource
{
    [CmdletBinding()]
    [OutputType([System.Collections.Hashtable])]
    param
    (
        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [System.String]$IpAddress
    )


    $networkAdapterConfiguration = Get-NetworkAdapterConfigurationByIpAddress $IpAddress

    if ($networkAdapterConfiguration -eq $null)
    {
        return @{
            IpAddress = $IpAddress
            Interface = $null
            SubnetMask = $null
            DHCPEnabled = $null
            Ensure = "Absent"
        }
    }

    $networkAdapter = Get-NetworkAdapterByIndex $networkAdapterConfiguration.Index
    $ipAddressList = $networkAdapterConfiguration.IPAddress | Where-IPv4Address
    $ipSubnetList = $networkAdapterConfiguration.IPSubnet | Where-IPv4Subnet
    $ipAddressIndex = $ipAddressList.IndexOf($IpAddress)

    return @{
        IpAddress = $IpAddress
        Interface = $networkAdapter.NetConnectionID
        SubnetMask = @($ipSubnetList)[$ipAddressIndex]
        DHCPEnabled = $networkAdapterConfiguration.DHCPEnabled
        Ensure = "Present"
    }
}

function Set-TargetResource
{
    [CmdletBinding()]
    param
    (
        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [System.String]$IpAddress,

        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [System.String]$Interface,

        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [System.String]$SubnetMask,

        [ValidateSet("Present","Absent")]
        [System.String]
        $Ensure  = "Present"
    )

    if(!([System.Net.Ipaddress]::TryParse($IpAddress, [ref]0))) { throw "IP Address ""$IpAddress"" is invalid"}
    if(!([System.Net.Ipaddress]::TryParse($SubnetMask, [ref]0))) { throw "SubnetMask ""$SubnetMask"" is invalid"}

    if ($Ensure -eq "Absent")
    {
        Remove-IpAddress -IpAddress $IpAddress -Interface $Interface
    }
    else
    {
        Add-IpAddress -IpAddress $IpAddress -Interface $Interface -SubnetMask $SubnetMask
    }
}

function Test-TargetResource
{
    [CmdletBinding()]
    param
    (
        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [System.String]$IpAddress,

        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [System.String]$Interface,

        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [System.String]$SubnetMask,

        [ValidateSet("Present","Absent")]
        [System.String]
        $Ensure  = "Present"
    )

    $existingIpAddress = Get-TargetResource $IpAddress

    if ($Ensure -eq "Present" -and `
        $existingIpAddress -ne $null -and `
        $existingIpAddress.Interface -eq $Interface -and `
        $existingIpAddress.SubnetMask -eq $SubnetMask -and `
        $existingIpAddress.Ensure -eq $Ensure -and `
        $existingIpAddress.DHCPEnabled -eq $false)
    {
        return $true
    }
    elseif ($Ensure -eq "Absent" -and `
        $existingIpAddress.Ensure -eq $Ensure)
    {
        return $true
    }

    return $false
}

function Add-IpAddress
{
    param
    (
        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [System.String]$IpAddress,

        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [System.String]$Interface,

        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [System.String]$SubnetMask
    )

    $networkAdapterConfiguration = Get-NetworkAdapterConfigurationByInterface $Interface

    if (Test-IpAddressBound -IpAddress $IpAddress -Index $networkAdapterConfiguration.Index -SubnetMask $SubnetMask) { return }

    if (Test-IpAddressBound $IpAddress)
    {
        Remove-IpAddress -IpAddress $IpAddress
    }

    $ipAddressList = $networkAdapterConfiguration.IPAddress + @($IpAddress) | Where-IPv4Address
    $ipSubnetList = $networkAdapterConfiguration.IPSubnet + @($SubnetMask) | Where-IPv4Subnet

    Enable-Static -NetworkAdapterConfiguration $networkAdapterConfiguration `
        -IpAddresses $ipAddressList `
        -IpSubnets $ipSubnetList
}

function Remove-IpAddress
{
    param
    (
        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [System.String]$IpAddress,

        [parameter(Mandatory = $false)]
        [System.String]$Interface = $null
    )

    $networkAdapterConfiguration = $null
    if ($Interface)
    {
        $networkAdapterConfiguration = Get-NetworkAdapterConfigurationByInterface $Interface
    }
    else
    {
        $networkAdapterConfiguration = Get-NetworkAdapterConfigurationByIpAddress $IpAddress
    }

    $ipAddressList = [System.Collections.ArrayList]@($networkAdapterConfiguration.IPAddress | Where-IPv4Address)
    $ipSubnetList = [System.Collections.ArrayList]@($networkAdapterConfiguration.IPSubnet | Where-IPv4Subnet)

    $ipAddressIndex = $ipAddressList.IndexOf($IpAddress)
    if ($ipAddressIndex -lt 0) {return}
    $ipAddressList.RemoveAt($ipAddressIndex)
    $ipSubnetList.RemoveAt($ipAddressIndex)

    if ($ipAddressList.Length -gt 0)
    {
        Enable-Static -NetworkAdapterConfiguration $networkAdapterConfiguration `
            -IpAddresses ([Object[]]$ipAddressList) `
            -IpSubnets ([Object[]]$ipSubnetList)
    }
    else
    {
        # Adapter is no longer bound to any IP addresses
        # Reverting adapter to DHCP
        Enable-DHCP -NetworkAdapterConfiguration $networkAdapterConfiguration
    }
}

function Where-IPv4Address
{
    [CmdletBinding()]
    param
    (
        [parameter(Mandatory = $true, ValueFromPipeline = $true)]
        [String]
        $InputObject
    )

    process
    {
        if ($InputObject -notmatch ":")
        {
            Write-Output $InputObject
        }
    }
}

function Where-IPv4Subnet
{
    [CmdletBinding()]
    param
    (
        [parameter(Mandatory = $true, ValueFromPipeline = $true)]
        [String]
        $InputObject
    )

    process
    {
        if ($InputObject -match "\d+\.\d+\.\d+\.\d+")
        {
            Write-Output $InputObject
        }
    }
}

function Get-NetworkAdapterByIndex
{
    param
    (
        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [Int32]$Index
    )

    $networkAdapter = Get-WmiObject Win32_NetworkAdapter | ? {$_.Index -eq $Index}
    $results = $networkAdapter | measure
    if ($results.count -le 0)
    {
        throw "Could not find a network adapter with index ""$Index"""
    }
    elseif ($results.count -gt 1)
    {
        $matchingAdapters = ($networkAdapter | % Path) -join ", "
        throw "Multiple network adapters match the index ""$Index"" {$matchingAdapters}"
    }

    return ($networkAdapter | Select-Object -First 1)
}

function Get-NetworkAdapterByInterface
{
    param
    (
        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [System.String]$Interface
    )



    $networkAdapter = Get-WmiObject Win32_NetworkAdapter | ? {$_.NetConnectionID -eq $Interface}
    $results = $networkAdapter | measure
    if ($results.count -le 0)
    {
        throw "Could not find a network adapter matching ""$Interface"""
    }
    elseif ($results.count -gt 1)
    {
        $matchingAdapters = ($networkAdapter | % Path) -join ", "
        throw "Multiple network adapters match the interface ""$Interface"" {$matchingAdapters}"
    }


    return ($networkAdapter | Select-Object -First 1)
}

function Get-NetworkAdapterConfigurationByInterface
{
    param
    (
        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [System.String]$Interface
    )

    $networkAdapter = Get-NetworkAdapterByInterface $Interface
    return (Get-WmiObject Win32_NetworkAdapterConfiguration | ? {$_.Index -eq $networkAdapter.Index} | Select-Object -First 1)
}

function Get-NetworkAdapterConfigurationByIpAddress
{
    param
    (
        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [System.String]$IpAddress
    )

    $networkAdapterConfiguration = Get-WmiObject Win32_NetworkAdapterConfiguration | ? {$_.IPAddress -contains $IpAddress}

    $results = $networkAdapterConfiguration | measure
    if ($results.count -gt 1)
    {
        $matchingAdapters = ($networkAdapterConfiguration | % Path) -join ", "
        throw "IP Address ""$IpAddress"" is bound to multiple network adapters {$matchingAdapters}"
    }

    return ($networkAdapterConfiguration | Select-Object -First 1)
}

function Test-IpAddressBound
{
    [OutputType([Boolean])]
    param
    (
        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [System.String]$IpAddress,

        [parameter(Mandatory = $false)]
        [ValidateNotNullOrEmpty()]
        [Int32]$Index,

        [parameter(Mandatory = $false)]
        [ValidateNotNullOrEmpty()]
        [System.String]$SubnetMask
    )

    $networkAdapterConfiguration = Get-WmiObject Win32_NetworkAdapterConfiguration | ? {$_.IPAddress -contains $IpAddress}

    if ($Index)
    {
        $networkAdapterConfiguration = $networkAdapterConfiguration | ? {$_.Index -eq $Index}
    }

    if ($SubnetMask)
    {
        $networkAdapterConfiguration = $networkAdapterConfiguration | ? {$_.IPSubnet[$_.IPAddress.IndexOf($IpAddress)] -eq $SubnetMask}
    }

    $results = $networkAdapterConfiguration | measure

    if ($results.count -le 0) { return $false } else { return $true }
}

function Enable-Static
{
    [CmdletBinding()]
    param
    (
        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [System.String[]]$IpAddresses,

        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [System.String[]]$IpSubnets,

        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [Object]$NetworkAdapterConfiguration
    )

    $result = $NetworkAdapterConfiguration.EnableStatic($IpAddresses, $IpSubnets)
    if ($result.ReturnValue -ne 0) { throw "Failed to enable static IP addresses on network adapter with index ""$($NetworkAdapterConfiguration.Index)"" {$($IpAddresses -join ", ")}"}
}

function Enable-DHCP
{
    [CmdletBinding()]
    param
    (
        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [Object]$NetworkAdapterConfiguration
    )

    $result = $NetworkAdapterConfiguration.EnableDHCP()
    if ($result.ReturnValue -ne 0) { throw "Failed to enable DHCP on network adapter with index ""$($NetworkAdapterConfiguration.Index)"""}
}

Export-ModuleMember -function Get-TargetResource, Set-TargetResource, Test-TargetResource
lib\cNetworking\DSCResources\SEEK_cStaticIpAddress\SEEK_cStaticIpAddress.schema.mof
 
lib\cNetworking\DSCResources\SEEK_cUrlReservation\SEEK_cUrlReservation.psm1
function Get-TargetResource
{
    [CmdletBinding()]
    [OutputType([System.Collections.Hashtable])]
    param
    (
        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]$Protocol = "http",

        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]$Hostname = "*",

        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]$Port
    )

    $url = Get-Url $Protocol $Hostname $Port
    $urlAclOutput = (Invoke-NetshUrlAcl -Protocol $Protocol -Operation "show" -Url $url)
    $urlReservationExists = $urlAclOutput -match "User:\s(.+?)\s"

    if (!$urlReservationExists)
    {
        return @{
            Protocol = $Protocol
            Hostname = $Hostname
            Port = $Port
            User = $null
            Ensure = "Absent"
        }
    }

    $user = $Matches[1]
    return @{
        Protocol = $Protocol
        Hostname = $Hostname
        Port = $Port
        User = $user
        Ensure = "Present"
    }
}

function Set-TargetResource
{
    [CmdletBinding(DefaultParameterSetName = "Absent")]
    param
    (
        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]$Protocol = "http",

        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]$Hostname = "*",

        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]$Port,

        [parameter(Mandatory=$true,ParameterSetName = "Present")]
        [ValidateNotNullOrEmpty()]
        [String]$User,

        [parameter(Mandatory=$false,ParameterSetName = "Present")]
        [parameter(Mandatory=$true,ParameterSetName = "Absent")]
        [ValidateSet("Present","Absent")]
        [System.String]
        $Ensure  = "Present"
    )

    if ($Ensure -eq "Present")
    {
        New-UrlReservation -Protocol $Protocol -Hostname $Hostname -Port $Port -User $User
    }
    else
    {
        Remove-UrlReservation -Protocol $Protocol -Hostname $Hostname -Port $Port
    }
}

function Test-TargetResource
{
    [CmdletBinding(DefaultParameterSetName = "Absent")]
    param
    (
        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]$Protocol = "http",

        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]$Hostname = "*",

        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]$Port,

        [parameter(Mandatory=$true,ParameterSetName = "Present")]
        [ValidateNotNullOrEmpty()]
        [String]$User,

        [parameter(Mandatory=$false,ParameterSetName = "Present")]
        [parameter(Mandatory=$true,ParameterSetName = "Absent")]
        [ValidateSet("Present","Absent")]
        [System.String]
        $Ensure  = "Present"
    )

    $urlReservation = Get-TargetResource -Protocol $Protocol -Hostname $Hostname -Port $Port

    if ($Ensure -eq "Absent" -and $urlReservation.Ensure -eq "Absent")
    {
        return $true
    }

    if ($Ensure -eq "Present" `
        -and $urlReservation.Ensure -eq "Present" `
        -and $urlReservation.Protocol -eq $Protocol `
        -and $urlReservation.Hostname -eq $Hostname `
        -and $urlReservation.Port -eq $Port `
        -and $urlReservation.User -eq $User)
    {
        return $true
    }

    return $false
}

function New-UrlReservation
{
    [CmdletBinding()]
    param
    (
        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]$Protocol = "http",

        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]$Hostname = "*",

        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]$Port,

        [ValidateNotNullOrEmpty()]
        [String]$User
    )

    $url = Get-Url $Protocol $Hostname $Port
    Invoke-NetshUrlAcl -Protocol $Protocol -Operation "add" -Url $url -User $User
}

function Remove-UrlReservation
{
    [CmdletBinding()]
    param
    (
        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]$Protocol = "http",

        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]$Hostname = "*",

        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]$Port
    )

    $url = Get-Url $Protocol $Hostname $Port
    Invoke-NetshUrlAcl -Protocol $Protocol -Operation "del" -Url $url
}

function Get-Url
{
    [CmdletBinding()]
    param
    (
        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]$Protocol = "http",

        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]$Hostname = "*",

        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]$Port
    )

    return "${Protocol}://${Hostname}:${Port}/"
}

function Invoke-NetshUrlAcl
{
    [CmdletBinding()]
    [OutputType([System.String])]
    param
    (
        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]$Protocol = "http",

        [parameter(Mandatory = $true)]
        [ValidateSet("add","del","show")]
        [String]$Operation,

        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]$Url,

        [String]$User
    )
    $argumentList = @(
        $Protocol, $Operation, 'urlacl',
        "url=""${Url}"""
    )
    if ($user)
    {
        $argumentList += "user=""${User}"""
    }
    $outputPath = "${env:TEMP}\netsh.out"
    $process = Start-Process netsh -ArgumentList $argumentList -Wait -NoNewWindow -RedirectStandardOutput $outputPath -Passthru
    if ($process.ExitCode -ne 0) { throw "Error performing operation '${Operation}' for reserved url"}
    return ((Get-Content $outputPath) -join "`n")
}


Export-ModuleMember -function Get-TargetResource, Set-TargetResource, Test-TargetResource
lib\cNetworking\DSCResources\SEEK_cUrlReservation\SEEK_cUrlReservation.schema.mof
 
tools\chocolateyInstall.ps1
try
{
	$DSCResourcesRoot = Join-Path $env:ProgramFiles "WindowsPowerShell\Modules"
	$DSCResourceTarget = Join-Path $env:chocolateyPackageFolder "lib"

	# remove DSC resources that may have been manually installed
	if (Test-Path "$DSCResourcesRoot\SEEK - Modules") {
		cmd /c rmdir "$DSCResourcesRoot\SEEK - Modules"
	}

	
	Get-ChildItem $DSCResourceTarget | Foreach-Object {
		if (Test-Path "$DSCResourcesRoot\$_") {
			# remove previous installation of this package
			cmd /c rmdir "$DSCResourcesRoot\$_"
		}
		cmd /c mklink /j "$DSCResourcesRoot\$_" "$DSCResourceTarget\$_"
		Get-ChildItem -Path "$DSCResourcesRoot\$_" -File -Recurse | Unblock-File
	}

} catch {
	$host.SetShouldExit(1)
	throw $_.Exception
}
tools\chocolateyUninstall.ps1
try
{
	$DSCResourcesRoot = Join-Path $env:ProgramFiles "WindowsPowerShell\Modules"
	$DSCResourceTarget = Join-Path $env:chocolateyPackageFolder "lib"
	Get-ChildItem $DSCResourceTarget | Foreach-Object { cmd /c rmdir "$DSCResourcesRoot\$_" }
} catch {
    throw $_.Exception
}

In cases where actual malware is found, the packages are subject to removal. Software sometimes has false positives. Moderators do not necessarily validate the safety of the underlying software, only that a package retrieves software from the official distribution point and/or validate embedded software against official distribution point (where distribution rights allow redistribution).

Chocolatey Pro provides runtime protection from possible malware.

Version Downloads Last Updated Status
SEEK DSC Networking 2.0.0-alpha9 270 Thursday, July 30, 2015 Approved
SEEK DSC Networking 2.0.0-alpha7 262 Friday, May 1, 2015 Approved
SEEK DSC Networking 2.0.0-alpha6 262 Wednesday, April 22, 2015 Approved
SEEK DSC Networking 2.0.0-alpha5 270 Tuesday, April 21, 2015 Approved
SEEK DSC Networking 2.0.0-alpha4 235 Tuesday, April 21, 2015 Approved
SEEK DSC Networking 2.0.0-alpha2 252 Tuesday, February 24, 2015 Approved
SEEK DSC Networking 2.0.0-alpha1 245 Monday, February 23, 2015 Approved

This package has no dependencies.

Discussion for the SEEK DSC Networking Package

Ground Rules:

  • This discussion is only about SEEK DSC Networking and the SEEK DSC Networking package. If you have feedback for Chocolatey, please contact the Google Group.
  • This discussion will carry over multiple versions. If you have a comment about a particular version, please note that in your comments.
  • The maintainers of this Chocolatey Package will be notified about new comments that are posted to this Disqus thread, however, it is NOT a guarantee that you will get a response. If you do not hear back from the maintainers after posting a message below, please follow up by using the link on the left side of this page or follow this link to contact maintainers. If you still hear nothing back, please follow the package triage process.
  • Tell us what you love about the package or SEEK DSC Networking, or tell us what needs improvement.
  • Share your experiences with the package, or extra configuration or gotchas that you've found.
  • If you use a url, the comment will be flagged for moderation until you've been whitelisted. Disqus moderated comments are approved on a weekly schedule if not sooner. It could take between 1-5 days for your comment to show up.
comments powered by Disqus