-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from dsccommunity/CMNetworkDiscovery
CMNetworkDiscovery: A resource to manage the network discovery method
- Loading branch information
Showing
9 changed files
with
403 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
source/DSCResources/DSC_CMNetworkDiscovery/DSC_CMNetworkDiscovery.psm1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
6 changes: 6 additions & 0 deletions
6
source/DSCResources/DSC_CMNetworkDiscovery/DSC_CMNetworkDiscovery.schema.mof
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
6 changes: 6 additions & 0 deletions
6
source/DSCResources/DSC_CMNetworkDiscovery/en-US/DSC_CMNetworkDiscovery.strings.psd1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}. | ||
'@ |
17 changes: 17 additions & 0 deletions
17
source/Examples/Resources/CMNetworkDiscovery/CMNetworkDiscovery_Disabled.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
source/Examples/Resources/CMNetworkDiscovery/CMNetworkDiscovery_Enabled.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
Oops, something went wrong.