Skip to content

Commit

Permalink
Merge pull request #41 from dsccommunity/CMNetworkDiscovery
Browse files Browse the repository at this point in the history
CMNetworkDiscovery: A resource to manage the network discovery method
  • Loading branch information
NEllis280 authored Jun 17, 2020
2 parents 5ed121f + 6b512fa commit 32fefa1
Show file tree
Hide file tree
Showing 9 changed files with 403 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added CMHeartbeatDiscovery module
- Added ConvertTo-ScheduleInterval to ResourceHelper
- Added CMServiceConnectionPoint Resource
- Added CMNetworkDiscovery Resource

### Changed

Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ Please check out common DSC Community [contributing guidelines](https://dsccommu
the distribution point role.
- **CMHeartbeatDiscovery**: Provides a resource to manage the Configuration Manager
Heartbeat Discovery method.
- **CMNetworkDiscovery**: Provides a resource to manage the Configuration Manager
Network Discovery method.
- **CMServiceConnectionPoint**: Provides a resource for creating and managing
the SCCM Service Connection Point role.

Expand Down Expand Up @@ -648,6 +650,18 @@ Please check out common DSC Community [contributing guidelines](https://dsccommu
- [CMHeartbeatDiscovery_Disabled](Source\Examples\Resources\CMHeartbeatDiscovery\CMHeartbeatDiscovery_Disabled.ps1)
- [CMHeartbeatDiscovery_Enabled](Source\Examples\Resources\CMHeartbeatDiscovery\CMHeartbeatDiscovery_Enabled.ps1)

### CMNetworkDiscovery

- **[String] SiteCode** _(Key)_: Specifies the Site Code for the Configuration
Manager site.
- **[Boolean] Enabled** _(Required)_: Specifies the enablement of the network
discovery method.

#### CMNetworkDiscovery Examples

- [CMNetworkDiscovery_Disabled](Source\Examples\Resources\CMNetworkDiscovery\CMNetworkDiscovery_Disabled.ps1)
- [CMNetworkDiscovery_Enabled](Source\Examples\Resources\CMNetworkDiscovery\CMNetworkDiscovery_Enabled.ps1)

### CMServiceConnectionPoint

- **[String] SiteCode** _(Key)_: Specifies the Site Code for the Configuration
Expand Down
3 changes: 2 additions & 1 deletion source/ConfigMgrCBDsc.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
'CMDistributionPoint'
'CMHeartbeatDiscovery'
'CMServiceConnectionPoint'
'CMNetworkDiscovery'
)

<#
Expand All @@ -75,7 +76,7 @@
Tags = @('DesiredStateConfiguration', 'DSC', 'DSCResourceKit', 'DSCResource', 'ConfigMgrCBDsc','CMAccounts','SCCMPreReqs',
'SccmSqlSetup','SCCMInstall','CMIniFile','Collections','Boundaries','ForestDiscovery','ClientStatusSettings','BoundaryGroups',
'ManagementPoint','AssetIntelligencePoint','FallbackStatusPoint','SoftwareUpdatePoint','DistrubtionPoint','HeartbeatDiscovery',
'ServiceConnectionPoint')
'ServiceConnectionPoint','NetworkDiscovery')

# A URL to the license for this module.
LicenseUri = 'https://github.com/dsccommunity/ConfigMgrCBDsc/blob/master/LICENSE'
Expand Down
148 changes: 148 additions & 0 deletions source/DSCResources/DSC_CMNetworkDiscovery/DSC_CMNetworkDiscovery.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
$script:dscResourceCommonPath = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\DscResource.Common'
$script:configMgrResourcehelper = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\ConfigMgrCBDsc.ResourceHelper'

Import-Module -Name $script:dscResourceCommonPath
Import-Module -Name $script:configMgrResourcehelper

$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US'

<#
.SYNOPSIS
This will return a hashtable of results.
.PARAMETER SiteCode
Specifies the site code for Configuration Manager site.
.PARAMETER Enabled
Specifies the enablement of the Network discovery method.
When setting enabled to true, Network Discovery will be enabled with default settings.
Not used in Get-TargetResource.
#>
function Get-TargetResource
{
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
(
[Parameter(Mandatory = $true)]
[String]
$SiteCode,

[Parameter(Mandatory = $true)]
[Boolean]
$Enabled
)

Write-Verbose -Message $script:localizedData.RetrieveSettingValue
Import-ConfigMgrPowerShellModule -SiteCode $SiteCode
Set-Location -Path "$($SiteCode):\"

$networkDiscovery = (Get-CMDiscoveryMethod -Name NetworkDiscovery -SiteCode $SiteCode).Props
$enabledStatus = ($networkDiscovery | Where-Object -FilterScript {$_.PropertyName -eq 'Discovery Enabled'}).value1

if ($enabledStatus -eq 'FALSE')
{
$enable = $false
}
elseif ($enabledStatus -eq 'TRUE')
{
$enable = $true
}

return @{
SiteCode = $SiteCode
Enabled = $enable
}
}

<#
.SYNOPSIS
This will set the desired state.
.PARAMETER SiteCode
Specifies the site code for Configuration Manager site.
.PARAMETER Enabled
Specifies the enablement of the Network discovery method.
When setting enabled to true, Network Discovery will be enabled with default settings.
#>
function Set-TargetResource
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[String]
$SiteCode,

[Parameter(Mandatory = $true)]
[Boolean]
$Enabled
)

Import-ConfigMgrPowerShellModule -SiteCode $SiteCode
Set-Location -Path "$($SiteCode):\"

try
{
$state = Get-TargetResource -SiteCode $SiteCode -Enabled $Enabled

if ($Enabled -ne $state.Enabled)
{
Write-Verbose -Message ($script:localizedData.SettingEnable -f $state.Enabled, $Enabled)
Set-CMDiscoveryMethod -NetworkDiscovery -SiteCode $SiteCode -Enabled $Enabled
}
}
catch
{
throw $_
}
finally
{
Set-Location -Path "$env:temp"
}
}

<#
.SYNOPSIS
This will test the desired state.
.PARAMETER SiteCode
Specifies the site code for Configuration Manager site.
.PARAMETER Enabled
Specifies the enablement of the Network discovery method.
When setting enabled to true, Network Discovery will be enabled with default settings.
#>
function Test-TargetResource
{
[CmdletBinding()]
[OutputType([System.Boolean])]
param
(
[Parameter(Mandatory = $true)]
[String]
$SiteCode,

[Parameter(Mandatory = $true)]
[Boolean]
$Enabled
)

Import-ConfigMgrPowerShellModule -SiteCode $SiteCode
Set-Location -Path "$($SiteCode):\"
$state = Get-TargetResource -SiteCode $SiteCode -Enabled $Enabled
$result = $true

if ($Enabled -ne $state.Enabled)
{
Write-Verbose -Message ($script:localizedData.EnableStatus -f $Enabled, $state.Enabled)
$result = $false
}

Write-Verbose -Message ($script:localizedData.TestState -f $result)
return $result
}

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[ClassVersion("1.0.0"), FriendlyName("CMNetworkDiscovery")]
class DSC_CMNetworkDiscovery: OMI_BaseResource
{
[Key, Description("Specifies the SiteCode for the Configuration Manager site.")] String SiteCode;
[Required, Description("Specifies the enablement of the network discovery method. When setting enabled to true, Network Discovery will be enabled with default settings.")] Boolean Enabled;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ConvertFrom-StringData @'
RetrieveSettingValue = Getting results for Configuration Manager Network Discovery.
EnableStatus = Network discovery is set to {0} return {1}.
TestState = Test-TargetResource compliance check returned: {0}.
SettingEnable = Network discovery is currently {0}, setting to {1}.
'@
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<#
.SYNOPSIS
A DSC configuration script to disable Network Discovery for Configuration Manager.
#>
Configuration Example
{
Import-DscResource -ModuleName ConfigMgrCBDsc

Node localhost
{
CMNetworkDiscovery ExampleSettings
{
SiteCode = 'Lab'
Enabled = $false
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<#
.SYNOPSIS
A DSC configuration script to enable Network Discovery for Configuration Manager.
#>
Configuration Example
{
Import-DscResource -ModuleName ConfigMgrCBDsc

Node localhost
{
CMNetworkDiscovery ExampleSettings
{
SiteCode = 'Lab'
Enabled = $true
}
}
}
Loading

0 comments on commit 32fefa1

Please sign in to comment.