Skip to content

Commit

Permalink
Merge pull request #88 from PowerShell/dev
Browse files Browse the repository at this point in the history
Merging release pull request
  • Loading branch information
KarolKaczmarek committed Feb 2, 2016
2 parents d9b6110 + b6968a2 commit 344eb91
Show file tree
Hide file tree
Showing 38 changed files with 4,109 additions and 2,092 deletions.
171 changes: 171 additions & 0 deletions DSCResources/MSFT_xDhcpClient/MSFT_xDhcpClient.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
data LocalizedData
{
# culture="en-US"
ConvertFrom-StringData -StringData @'
GettingDHCPClientMessage=Getting the DHCP Client on {1} interface "{0}".
ApplyingDHCPClientMessage=Applying the DHCP Client on {1} interface "{0}".
DHCPClientSetStateMessage=DHCP Client was set to the desired state {2} on {1} interface "{0}".
CheckingDHCPClientMessage=Checking the DHCP Client on {1} interface "{0}".
DHCPClientDoesNotMatchMessage=DHCP Client is not in the desired state {2} on {1} interface "{0}".
InterfaceNotAvailableError=Interface "{0}" is not available. Please select a valid interface and try again.
'@
}

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

[Parameter(Mandatory)]
[ValidateSet('IPv4', 'IPv6')]
[String] $AddressFamily,

[Parameter(Mandatory)]
[ValidateSet('Enabled', 'Disabled')]
[String] $State
)

Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): "
$($LocalizedData.GettingDHCPClientMessage) `
-f $InterfaceAlias,$AddressFamily `
) -join '')

Test-ResourceProperty @PSBoundParameters

$CurrentDHCPClient = Get-NetIPInterface `
-InterfaceAlias $InterfaceAlias `
-AddressFamily $AddressFamily

$returnValue = @{
State = $CurrentDHCPClient.Dhcp
AddressFamily = $AddressFamily
InterfaceAlias = $InterfaceAlias
}

$returnValue
}

function Set-TargetResource
{
param
(
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[String] $InterfaceAlias,

[Parameter(Mandatory)]
[ValidateSet('IPv4', 'IPv6')]
[String] $AddressFamily,

[Parameter(Mandatory)]
[ValidateSet('Enabled', 'Disabled')]
[String] $State
)

Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): "
$($LocalizedData.ApplyingDHCPClientMessage) `
-f $InterfaceAlias,$AddressFamily `
) -join '')

Test-ResourceProperty @PSBoundParameters

$CurrentDHCPClient = Get-NetIPInterface `
-InterfaceAlias $InterfaceAlias `
-AddressFamily $AddressFamily

# The DHCP Client is in a different state - so change it.
Set-NetIPInterface `
-InterfaceAlias $InterfaceAlias `
-AddressFamily $AddressFamily `
-Dhcp $State `
-ErrorAction Stop

Write-Verbose -Message ( @("$($MyInvocation.MyCommand): "
$($LocalizedData.DHCPClientSetStateMessage) `
-f $InterfaceAlias,$AddressFamily,$State `
) -join '' )

} # Set-TargetResource

function Test-TargetResource
{
[OutputType([System.Boolean])]
param
(
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[String] $InterfaceAlias,

[Parameter(Mandatory)]
[ValidateSet('IPv4', 'IPv6')]
[String] $AddressFamily,

[Parameter(Mandatory)]
[ValidateSet('Enabled', 'Disabled')]
[String] $State
)

# Flag to signal whether settings are correct
[Boolean] $desiredConfigurationMatch = $true

Write-Verbose -Message ( @("$($MyInvocation.MyCommand): "
$($LocalizedData.CheckingDHCPClientMessage)
) -join '')

Test-ResourceProperty @PSBoundParameters

$CurrentDHCPClient = Get-NetIPInterface `
-InterfaceAlias $InterfaceAlias `
-AddressFamily $AddressFamily

# The DHCP Client is in a different state - so change it.
if ($CurrentDHCPClient.DHCP -ne $State)
{
Write-Verbose -Message ( @("$($MyInvocation.MyCommand): "
$($LocalizedData.DHCPClientDoesNotMatchMessage) `
-f $InterfaceAlias,$AddressFamily,$State `
) -join '' )
$desiredConfigurationMatch = $false
}

return $desiredConfigurationMatch
} # Test-TargetResource

function Test-ResourceProperty {
# Function will check the interface exists.
# If any problems are detected an exception will be thrown.
[CmdletBinding()]
param
(
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[String] $InterfaceAlias,

[Parameter(Mandatory)]
[ValidateSet('IPv4', 'IPv6')]
[String] $AddressFamily,

[Parameter(Mandatory)]
[ValidateSet('Enabled', 'Disabled')]
[String] $State
)

if (-not (Get-NetAdapter | Where-Object -Property Name -EQ $InterfaceAlias ))
{
$errorId = 'InterfaceNotAvailable'
$errorCategory = [System.Management.Automation.ErrorCategory]::DeviceError
$errorMessage = $($LocalizedData.InterfaceNotAvailableError) -f $InterfaceAlias
$exception = New-Object -TypeName System.InvalidOperationException `
-ArgumentList $errorMessage
$errorRecord = New-Object -TypeName System.Management.Automation.ErrorRecord `
-ArgumentList $exception, $errorId, $errorCategory, $null

$PSCmdlet.ThrowTerminatingError($errorRecord)
}
} # Test-ResourceProperty

Export-ModuleMember -function *-TargetResource
7 changes: 7 additions & 0 deletions DSCResources/MSFT_xDhcpClient/MSFT_xDhcpClient.schema.mof
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[ClassVersion("1.0.0"), FriendlyName("xDHCPClient")]
class MSFT_xDHCPClient: OMI_BaseResource
{
[Required,ValueMap{"Enabled", "Disabled"},Values{"Enabled", "Disabled"}] string State;
[Key] string InterfaceAlias;
[Key,Write,ValueMap{"IPv4", "IPv6"},Values{"IPv4", "IPv6"}] string AddressFamily;
};
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function Get-TargetResource
$dnsClient = Get-DnsClient -InterfaceAlias $InterfaceAlias -ErrorAction SilentlyContinue;
$targetResource = @{
InterfaceAlias = $dnsClient.InterfaceAlias;
DnsSuffix = $dnsClient.ConnectionSpecificSuffix;
ConnectionSpecificSuffix = $dnsClient.ConnectionSpecificSuffix;
RegisterThisConnectionsAddress = $dnsClient.RegisterThisConnectionsAddress;
UseSuffixWhenRegistering = $dnsClient.UseSuffixWhenRegistering;
}
Expand Down
7 changes: 7 additions & 0 deletions DSCResources/MSFT_xFirewall/MSFT_xFirewall.Schema.mof
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@ class MSFT_xFirewall : OMI_BaseResource
[Write, Description("Specifies that network packets with matching IP addresses match this rule")] String RemoteAddress[];
[Write, Description("Specifies that matching IPsec rules of the indicated computer accounts are created")] String RemoteMachine;
[Write, Description("Specifies that matching IPsec rules of the indicated user accounts are created")] String RemoteUser;
[Write, Description("Specifies a dynamic transport"), ValueMap{"Any","ProximityApps","ProximitySharing","WifiDirectPrinting","WifiDirectDisplay","WifiDirectDevices"},Values{"Any","ProximityApps","ProximitySharing","WifiDirectPrinting","WifiDirectDisplay","WifiDirectDevices"}] String DynamicTransport;
[Write, Description("Specifies that matching firewall rules of the indicated edge traversal policy are created"), ValueMap{"Block","Allow","DeferToUser","DeferToApp"},Values{"Block","Allow","DeferToUser","DeferToApp"}] String EdgeTraversalPolicy;
[Write, Description("Specifies the ICMP type codes")] String IcmpType[];
[Write, Description("Indicates that matching firewall rules of the indicated value are created")] Boolean LocalOnlyMapping;
[Write, Description("Indicates that matching firewall rules of the indicated value are created")] Boolean LooseSourceMapping;
[Write, Description("Indicates that matching network traffic that would otherwise be blocked are allowed")] Boolean OverrideBlockRules;
[Write, Description("Specifies that matching firewall rules of the indicated owner are created")] String Owner;
};
82 changes: 79 additions & 3 deletions DSCResources/MSFT_xFirewall/MSFT_xFirewall.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ data ParameterList
@{ Name = 'RemoteAddress'; Source = '$properties.AddressFilters.RemoteAddress'; Type = 'Array' }
@{ Name = 'RemoteMachine'; Source = '$properties.SecurityFilters.RemoteMachine'; Type = 'String' }
@{ Name = 'RemoteUser'; Source = '$properties.SecurityFilters.RemoteUser'; Type = 'String' }
@{ Name = 'DynamicTransport'; Source = '$properties.PortFilters.DynamicTransport'; Type = 'String' }
@{ Name = 'EdgeTraversalPolicy'; Source = '$FirewallRule.EdgeTraversalPolicy'; Type = 'String' }
@{ Name = 'IcmpType'; Source = '$properties.PortFilters.IcmpType'; Type = 'Array' }
@{ Name = 'LocalOnlyMapping'; Source = '$FirewallRule.LocalOnlyMapping'; Type = 'Boolean' }
@{ Name = 'LooseSourceMapping'; Source = '$FirewallRule.LooseSourceMapping'; Type = 'Boolean' }
@{ Name = 'OverrideBlockRules'; Source = '$properties.SecurityFilters.OverrideBlockRules'; Type = 'Boolean' }
@{ Name = 'Owner'; Source = '$FirewallRule.Owner'; Type = 'String' }
)
}

Expand Down Expand Up @@ -236,7 +243,32 @@ function Set-TargetResource

# Specifies that matching IPsec rules of the indicated user accounts are created
[ValidateNotNullOrEmpty()]
[String] $RemoteUser
[String] $RemoteUser,

# Specifies a dynamic transport
[ValidateSet('Any','ProximityApps','ProximitySharing','WifiDirectPrinting','WifiDirectDisplay','WifiDirectDevices')]
[String] $DynamicTransport,

# Specifies that matching firewall rules of the indicated edge traversal policy are created
[ValidateSet('Block','Allow','DeferToUser','DeferToApp')]
[String] $EdgeTraversalPolicy,

# Specifies the ICMP type codes
[ValidateNotNullOrEmpty()]
[String[]] $IcmpType,

# Indicates that matching firewall rules of the indicated value are created
[Boolean] $LocalOnlyMapping,

# Indicates that matching firewall rules of the indicated value are created
[Boolean] $LooseSourceMapping,

# Indicates that matching network traffic that would otherwise be blocked are allowed
[Boolean] $OverrideBlockRules,

# Specifies that matching firewall rules of the indicated owner are created
[ValidateNotNullOrEmpty()]
[String] $Owner
)

Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): "
Expand Down Expand Up @@ -465,7 +497,32 @@ function Test-TargetResource

# Specifies that matching IPsec rules of the indicated user accounts are created
[ValidateNotNullOrEmpty()]
[String] $RemoteUser
[String] $RemoteUser,

# Specifies a dynamic transport
[ValidateSet('Any','ProximityApps','ProximitySharing','WifiDirectPrinting','WifiDirectDisplay','WifiDirectDevices')]
[String] $DynamicTransport,

# Specifies that matching firewall rules of the indicated edge traversal policy are created
[ValidateSet('Block','Allow','DeferToUser','DeferToApp')]
[String] $EdgeTraversalPolicy,

# Specifies the ICMP type codes
[ValidateNotNullOrEmpty()]
[String[]] $IcmpType,

# Indicates that matching firewall rules of the indicated value are created
[Boolean] $LocalOnlyMapping,

# Indicates that matching firewall rules of the indicated value are created
[Boolean] $LooseSourceMapping,

# Indicates that matching network traffic that would otherwise be blocked are allowed
[Boolean] $OverrideBlockRules,

# Specifies that matching firewall rules of the indicated owner are created
[ValidateNotNullOrEmpty()]
[String] $Owner
)

Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): "
Expand Down Expand Up @@ -548,7 +605,14 @@ function Test-RuleProperties
[String[]] $Platform,
[String[]] $RemoteAddress,
[String] $RemoteMachine,
[String] $RemoteUser
[String] $RemoteUser,
[String] $DynamicTransport,
[String] $EdgeTraversalPolicy,
[String[]] $IcmpType,
[Boolean] $LocalOnlyMapping,
[Boolean] $LooseSourceMapping,
[Boolean] $OverrideBlockRules,
[String] $Owner
)

$properties = Get-FirewallRuleProperty -FirewallRule $FirewallRule
Expand Down Expand Up @@ -576,6 +640,18 @@ function Test-RuleProperties
$desiredConfigurationMatch = $false
}
}
'Boolean'
{
# Perform a boolean comparison.
if ($ParameterNew -and ($ParameterSource -ne $ParameterNew))
{
Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): "
$($LocalizedData.PropertyNoMatchMessage) `
-f $parameter.Name,$ParameterSource,$ParameterNew
) -join '')
$desiredConfigurationMatch = $false
}
}
'Array'
{
# Array comparison uses Compare-Object
Expand Down
18 changes: 1 addition & 17 deletions DSCResources/MSFT_xIPAddress/MSFT_xIPAddress.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ SubnetMaskDoesNotMatchMessage=Subnet mask does NOT match desired state. Expected
SubnetMaskMatchMessage=Subnet mask is in desired state.
DHCPIsNotDisabledMessage=DHCP is NOT disabled.
DHCPIsAlreadyDisabledMessage=DHCP is already disabled.
DHCPIsNotTestedMessage=DHCP status is ignored when Address Family is IPv6.
InterfaceNotAvailableError=Interface "{0}" is not available. Please select a valid interface and try again.
AddressFormatError=Address "{0}" is not in the correct format. Please correct the Address parameter in the configuration and try again.
AddressIPv4MismatchError=Address "{0}" is in IPv4 format, which does not match server address family {1}. Please correct either of them in the configuration and try again.
Expand Down Expand Up @@ -229,23 +230,6 @@ function Test-TargetResource
) -join '' )
}
}

# Test if DHCP is already disabled
if (-not (Get-NetIPInterface `
-InterfaceAlias $InterfaceAlias `
-AddressFamily $AddressFamily).Dhcp.ToString().Equals('Disabled'))
{
Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): "
$($LocalizedData.DHCPIsNotDisabledMessage)
) -join '' )
$desiredConfigurationMatch = $false
}
else
{
Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): "
$($LocalizedData.DHCPIsAlreadyDisabledMessage)
) -join '' )
}
return $desiredConfigurationMatch
} # Test-TargetResource

Expand Down
Loading

0 comments on commit 344eb91

Please sign in to comment.