Skip to content

Commit

Permalink
Merge pull request #19 from PowerShell/dev
Browse files Browse the repository at this point in the history
Release of version 3.1.0.0 of xDFS
  • Loading branch information
kwirkykat authored Jun 29, 2016
2 parents 613ae58 + 4816f8d commit 78096cb
Show file tree
Hide file tree
Showing 12 changed files with 783 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
data LocalizedData
{
# culture="en-US"
ConvertFrom-StringData -StringData @'
GettingNamespaceServerConfigurationMessage=Getting DFS Namespace Server Configuration.
SettingNamespaceServerConfigurationMessage=Setting DFS Namespace Server Configuration.
NamespaceServerConfigurationUpdateParameterMessage=Setting DFS Namespace Server Configuration parameter {0} to "{1}".
NamespaceServerConfigurationUpdatedMessage=Setting DFS Namespace Server Configuration updated.
NamespaceServerConfigurationServiceRestartedMessage=DFS Namespace Server restarted.
TestingNamespaceServerConfigurationMessage=Testing DFS Namespace Server Configuration.
NamespaceServerConfigurationParameterNeedsUpdateMessage=DFS Namespace Server Configuration parameter "{0}" is "{1}" but should be "{2}". Change required.
'@
}

<#
This is an array of all the parameters used by this resource
If the property Restart is true then when this property is updated the service
Will be restarted.
#>
data ParameterList
{
@(
@{ Name = 'LdapTimeoutSec'; Type = 'Uint32' },
@{ Name = 'SyncIntervalSec'; Type = 'String' },
@{ Name = 'UseFQDN'; Type = 'Uint32'; Restart = $True }
)
}

function Get-TargetResource
{
[CmdletBinding()]
[OutputType([Hashtable])]
param
(
[parameter(Mandatory = $true)]
[ValidateSet('Yes')]
[String]
$IsSingleInstance
)

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

# The ComputerName will always be LocalHost unless a good reason can be provided to
# enable it as a parameter.
$ComputerName = 'LocalHost'

# Get the current DFSN Server Configuration
$ServerConfiguration = Get-DfsnServerConfiguration `
-ComputerName $ComputerName `
-ErrorAction Stop

# Generate the return object.
$ReturnValue = @{
IsSingleInstance = 'Yes'
}
foreach ($parameter in $ParameterList)
{
$ReturnValue += @{ $parameter.Name = $ServerConfiguration.$($parameter.name) }
} # foreach

return $ReturnValue
} # Get-TargetResource

function Set-TargetResource
{
[CmdletBinding()]
param
(
[parameter(Mandatory = $true)]
[ValidateSet('Yes')]
[String]
$IsSingleInstance,

[Uint32]
$LdapTimeoutSec,

[Uint32]
$SyncIntervalSec,

[Boolean]
$UseFQDN
)

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

# The ComputerName will always be LocalHost unless a good reason can be provided to
# enable it as a parameter.
$ComputerName = 'LocalHost'

# Get the current DFSN Server Configuration
$ServerConfiguration = Get-DfsnServerConfiguration `
-ComputerName $ComputerName `
-ErrorAction Stop

# Generate a list of parameters that will need to be changed.
$ChangeParameters = @{}
$Restart = $False
foreach ($parameter in $ParameterList)
{
$ParameterSource = $ServerConfiguration.$($parameter.name)
$ParameterNew = (Invoke-Expression -Command "`$$($parameter.name)")
if ($PSBoundParameters.ContainsKey($parameter.Name) `
-and ($ParameterSource -ne $ParameterNew))
{
$ChangeParameters += @{
$($parameter.name) = $ParameterNew
}
Write-Verbose -Message ( @(
"$($MyInvocation.MyCommand): "
$($LocalizedData.NamespaceServerConfigurationUpdateParameterMessage) `
-f $parameter.Name,$ParameterNew
) -join '' )
if ($parameter.Restart)
{
$Restart = $True
} # if
} # if
} # foreach
if ($ChangeParameters.Count -gt 0)
{
# Update any parameters that were identified as different
$null = Set-DfsnServerConfiguration `
-ComputerName $ComputerName `
@ChangeParameters `
-ErrorAction Stop

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

if ($Restart)
{
# Restart the DFS Service
$null = Restart-Service `
-Name DFS `
-Force `
-ErrorAction Stop

Write-Verbose -Message ( @(
"$($MyInvocation.MyCommand): "
$($LocalizedData.NamespaceServerConfigurationServiceRestartedMessage)
) -join '' )
}
} # if
} # Set-TargetResource

function Test-TargetResource
{
[CmdletBinding()]
[OutputType([System.Boolean])]
param
(
[parameter(Mandatory = $true)]
[ValidateSet('Yes')]
[String]
$IsSingleInstance,

[Uint32]
$LdapTimeoutSec,

[Uint32]
$SyncIntervalSec,

[Boolean]
$UseFQDN
)

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

# The ComputerName will always be LocalHost unless a good reason can be provided to
# enable it as a parameter.
$ComputerName = 'LocalHost'

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

# Get the current DFSN Server Configuration
$ServerConfiguration = Get-DfsnServerConfiguration `
-ComputerName $ComputerName `
-ErrorAction Stop

# Check each parameter
foreach ($parameter in $ParameterList)
{
$ParameterSource = $ServerConfiguration.$($parameter.name)
$ParameterNew = (Invoke-Expression -Command "`$$($parameter.name)")
if ($PSBoundParameters.ContainsKey($parameter.Name) `
-and ($ParameterSource -ne $ParameterNew)) {
Write-Verbose -Message ( @(
"$($MyInvocation.MyCommand): "
$($LocalizedData.NamespaceServerConfigurationParameterNeedsUpdateMessage) `
-f $parameter.Name,$ParameterSource,$ParameterNew
) -join '' )
$desiredConfigurationMatch = $false
} # if
} # foreach

return $DesiredConfigurationMatch
} # Test-TargetResource

# Helper Functions
function New-TerminatingError
{
[CmdletBinding()]
param
(
[Parameter(Mandatory)]
[String] $ErrorId,

[Parameter(Mandatory)]
[String] $ErrorMessage,

[Parameter(Mandatory)]
[System.Management.Automation.ErrorCategory] $ErrorCategory
)

$exception = New-Object `
-TypeName System.InvalidOperationException `
-ArgumentList $errorMessage
$errorRecord = New-Object `
-TypeName System.Management.Automation.ErrorRecord `
-ArgumentList $exception, $errorId, $errorCategory, $null
$PSCmdlet.ThrowTerminatingError($errorRecord)
}

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[ClassVersion("1.0.0.0"), FriendlyName("xDFSNamespaceServerConfiguration")]
class MSFT_xDFSNamespaceServerConfiguration : OMI_BaseResource
{
[Key, Description("Specifies the resource is a single instance, the value must be 'Yes'"), ValueMap{"Yes"}, Values{"Yes"}] String IsSingleInstance;
[Write, Description("Specifies a time-out value, in seconds, for Lightweight Directory Access Protocol (LDAP) requests for the DFS namespace server.")] Uint32 LdapTimeoutSec;
[Write, Description("This interval controls how often domain-based DFS namespace root servers and domain controllers connect to the PDC emulator to get updates of DFS namespace metadata.")] Uint32 SyncIntervalSec;
[Write, Description("Indicates whether a DFS namespace server uses FQDNs in referrals.")] Boolean UseFQDN;
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Configuration DFSNamespace_Standalone_Public
Configuration DFSNamespace_Standalone
{
param
(
Expand All @@ -12,10 +12,10 @@ Configuration DFSNamespace_Standalone_Public
{
# Install the Prerequisite features first
# Requires Windows Server 2012 R2 Full install
WindowsFeature RSATDFSMgmtConInstall
{
Ensure = "Present"
Name = "RSAT-DFS-Mgmt-Con"
WindowsFeature RSATDFSMgmtConInstall
{
Ensure = "Present"
Name = "RSAT-DFS-Mgmt-Con"
}

WindowsFeature DFS
Expand Down Expand Up @@ -56,13 +56,13 @@ $ConfigData = @{
}
)
}
DFSNamespace_Standalone_Public `
DFSNamespace_Standalone `
-configurationData $ConfigData `
-Credential (Get-Credential -Message "Domain Credentials")
Start-DscConfiguration `
-Wait `
-Force `
-Verbose `
-ComputerName $ComputerName `
-Path $PSScriptRoot\DFSNamespace_Standalone_Public `
-Path $PSScriptRoot\DFSNamespace_Standalone `
-Credential (Get-Credential -Message "Local Admin Credentials on Remote Machine")
76 changes: 76 additions & 0 deletions Examples/Sample_xDFSNamespace_Standalone_FQDN.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
Configuration DFSNamespace_Standalone_FQDN
{
param
(
[Parameter(Mandatory)]
[pscredential] $Credential
)

Import-DscResource -ModuleName 'xDFS'

Node $NodeName
{
# Install the Prerequisite features first
# Requires Windows Server 2012 R2 Full install
WindowsFeature RSATDFSMgmtConInstall
{
Ensure = "Present"
Name = "RSAT-DFS-Mgmt-Con"
}

WindowsFeature DFS
{
Name = 'FS-DFS-Namespace'
Ensure = 'Present'
}

# Configure the namespace server
xDFSNamespaceServerConfiguration DFSNamespaceConfig
{
IsSingleInstance = 'Yes'
UseFQDN = $true
PsDscRunAsCredential = $Credential
} # End of xDFSNamespaceServerConfiguration Resource

# Configure the namespace
xDFSNamespaceRoot DFSNamespaceRoot_Standalone_Public
{
Path = '\\fileserver1.contoso.com\public'
TargetPath = '\\fileserver1.contoso.com\public'
Ensure = 'present'
Type = 'Standalone'
Description = 'Standalone DFS namespace for storing public files'
PsDscRunAsCredential = $Credential
} # End of DFSNamespaceRoot Resource

# Configure the namespace folder
xDFSNamespaceFolder DFSNamespaceFolder_Standalone_PublicBrochures
{
Path = '\\fileserver1.contoso.com\public\brochures'
TargetPath = '\\fileserver2.contoso.com\brochures'
Ensure = 'present'
Description = 'Standalone DFS namespace for storing public brochure files'
PsDscRunAsCredential = $Credential
} # End of DFSNamespaceFolder Resource
}
}
$ComputerName = Read-Host -Prompt 'Computer Name'
$ConfigData = @{
AllNodes = @(
@{
Nodename = $ComputerName
CertificateFile = "C:\publicKeys\targetNode.cer"
Thumbprint = "AC23EA3A9E291A75757A556D0B71CBBF8C4F6FD8"
}
)
}
DFSNamespace_Standalone_FQDN `
-configurationData $ConfigData `
-Credential (Get-Credential -Message "Domain Credentials")
Start-DscConfiguration `
-Wait `
-Force `
-Verbose `
-ComputerName $ComputerName `
-Path $PSScriptRoot\DFSNamespace_Standalone_FQDN `
-Credential (Get-Credential -Message "Local Admin Credentials on Remote Machine")
Loading

0 comments on commit 78096cb

Please sign in to comment.