Asked by:
What am I doing wrong in this script the error message is at the bottom of the script

Question
-
Find-Module xPSDesiredStateConfiguration | Install-Module -Force
configuration DSCPullServer{
param (
)
Import-DscResource -ModuleName PSDesiredStateConfiguration;
[parameter(Mandatory = $true)]
[string[]]$NodeName
)
Import-DSCResource -ModuleName xPSDesiredStateConfiguration
Node $NodeName {
WindowsFeature DSCServiceFeature {
Ensure = "Present"
Name = "DSC-Service"
}
xDscWebService PSDSCPullServer {
Ensure = "Present"
EndpointName = "PSDSCPullServer"
Port = 8080
PhysicalPath = "$env:SystemDrive\inetpub\wwwroot\PSDSCPullServer"
CertificateThumbPrint = "AllowUnencryptedTraffic"
ModulePath = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Modules"
ConfigurationPath = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Configuration"
State = "Started"
DependsOn = "[WindowsFeature]DSCServiceFeature"
UseSecurityBestPractices = $false
}
}
}
DSCPullServer -OutputPath c:\PS\DSC -NodeName LAB9DC1
Start-DscConfiguration -path c:\PS\DSC -verbose -wait
Configuration ConfigOfTheLCM {
param (
[parameter(Mandatory = $true)]
[string[]]$NodeName,
[parameter(Mandatory = $true)]
[string]$ConfigurationId,
[parameter(Mandatory = $true)]
[string]$DscUrl
)
Node $nodeName
{
LocalConfigurationManager
{
ConfigurationMode = "ApplyAndAutoCorrect"
ConfigurationID = $ConfigurationId
RefreshMode = "Pull"
AllowModuleOverwrite = $true
RebootNodeIfNeeded = $true
ConfigurationModeFrequencyMins = 30
RefreshFrequencyMins = 30
DownloadManagerName = "WebDownloadManager"
DownloadManagerCustomData = @{
ServerUrl = $DscUrl
AllowUnsecureConnection = "true"
}
}
}
}
$ConfigOfTheDSCAgentParams = @{
OutputPath = "c:\ps\dsc"
NodeName = "LAB9SRV1"
ConfigurationID = "00000000-0000-0000-0000-000000000001"
DscUrl = "http://LAB9DC1.powershell.local:8080/PSDSCPullServer.svc"
}
ConfigOfTheLCM @ConfigOfTheDSCAgentParams
Set-DscLocalConfigurationManager -Path c:\ps\dsc -Verbose
md c:\ps
"Hello Pull Server" | Out-File -FilePath c:\ps\PullFile.txt
New-SmbShare -Name PS -Path c:\ps -FullAccess everyone
Configuration SamplePulledConfig {
param([string[]]$NodeName)
Node $NodeName
{
file sampleFile {
SourcePath = "\\lab9dc1\ps\PullFile.txt"
DestinationPath = "c:\pulled\PullFile.txt"
}
}
}
SamplePulledConfig -NodeName 00000000-0000-0000-0000-000000000001 -OutputPath "$env:PROGRAMFILES\WindowsPowerShell\DscService\Configuration" -Verbose
New-DscChecksum "$env:PROGRAMFILES\WindowsPowerShell\DscService\Configuration" -Force -Verbose
Update-DscConfiguration -CimSession lab9srv1 -Wait -Verbose.
At line:2 char:28
+ configuration DSCPullServer{
+ ~
Missing closing '}' in statement block or type definition.
At line:29 char:1
+ }
+ ~
Unexpected token '}' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingEndCurlyBraceSunday, June 4, 2017 10:45 PM
All replies
-
Message is explicit:
At line:2 char:28
+ configuration DSCPullServer{
+ ~
Missing closing '}' in statement block or type definition\_(ツ)_/
Sunday, June 4, 2017 11:25 PM -
Hint: open in ISE and look for the little red squiggles which tell you where the issues are.
Also format you code correctly so you can see how the closures line up. You will find many issues with the code. Do you know who wrote the original before you changed it?
\_(ツ)_/
- Edited by jrv Sunday, June 4, 2017 11:28 PM
Sunday, June 4, 2017 11:26 PM -
Hi Mike,
This one works:
Find-Module xPSDesiredStateConfiguration | Install-Module -Force Import-DscResource -ModuleName PSDesiredStateConfiguration Import-DSCResource -ModuleName xPSDesiredStateConfiguration configuration DSCPullServer{ param( [parameter(Mandatory = $true)] [string[]]$NodeName ) Node $NodeName { WindowsFeature DSCServiceFeature { Ensure = "Present" Name = "DSC-Service" } xDscWebService PSDSCPullServer { Ensure = "Present" EndpointName = "PSDSCPullServer" Port = 8080 PhysicalPath = "$env:SystemDrive\inetpub\wwwroot\PSDSCPullServer" CertificateThumbPrint = "AllowUnencryptedTraffic" ModulePath = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Modules" ConfigurationPath = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Configuration" State = "Started" DependsOn = "[WindowsFeature]DSCServiceFeature" UseSecurityBestPractices = $false } } } DSCPullServer -OutputPath c:\PS\DSC -NodeName LAB9DC1 Start-DscConfiguration -path c:\PS\DSC -verbose -wait Configuration ConfigOfTheLCM { param ( [parameter(Mandatory = $true)] [string[]]$NodeName, [parameter(Mandatory = $true)] [string]$ConfigurationId, [parameter(Mandatory = $true)] [string]$DscUrl ) Node $nodeName { LocalConfigurationManager { ConfigurationMode = "ApplyAndAutoCorrect" ConfigurationID = $ConfigurationId RefreshMode = "Pull" AllowModuleOverwrite = $true RebootNodeIfNeeded = $true ConfigurationModeFrequencyMins = 30 RefreshFrequencyMins = 30 DownloadManagerName = "WebDownloadManager" DownloadManagerCustomData = @{ ServerUrl = $DscUrl AllowUnsecureConnection = "true" } } } } $ConfigOfTheDSCAgentParams = @{ OutputPath = "c:\ps\dsc" NodeName = "LAB9SRV1" ConfigurationID = "00000000-0000-0000-0000-000000000001" DscUrl = "http://LAB9DC1.powershell.local:8080/PSDSCPullServer.svc" } ConfigOfTheLCM @ConfigOfTheDSCAgentParams Set-DscLocalConfigurationManager -Path c:\ps\dsc -Verbose md c:\ps "Hello Pull Server" | Out-File -FilePath c:\ps\PullFile.txt New-SmbShare -Name PS -Path c:\ps -FullAccess everyone Configuration SamplePulledConfig { param([string[]]$NodeName) Node $NodeName { file sampleFile { SourcePath = "\\lab9dc1\ps\PullFile.txt" DestinationPath = "c:\pulled\PullFile.txt" } } } SamplePulledConfig -NodeName 00000000-0000-0000-0000-000000000001 -OutputPath "$env:PROGRAMFILES\WindowsPowerShell\DscService\Configuration" -Verbose New-DscChecksum "$env:PROGRAMFILES\WindowsPowerShell\DscService\Configuration" -Force -Verbose Update-DscConfiguration -CimSession lab9srv1 -Wait -Verbose
The standard format should like this:
https://msdn.microsoft.com/en-us/powershell/dsc/configurations
Best regards,
Andy
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.- Edited by Hello_2018 Tuesday, June 6, 2017 8:48 AM
- Proposed as answer by Hello_2018 Thursday, June 22, 2017 6:58 AM
Tuesday, June 6, 2017 8:46 AM -
Hi ,
did this issue was resolved?
if not please share the current situation for further assistance.
Best regards,
Andy
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.Tuesday, June 13, 2017 3:04 AM