Author Posts

March 7, 2017 at 5:19 am

Hello

When running the code below im getting this error, any idea whats wrong in the config?

PSDesiredStateConfiguration\Configuration : Cannot convert value "False" to type
"System.Management.Automation.ScriptBlock". Error: "Invalid cast from 'System.Boolean' to
'System.Management.Automation.ScriptBlock'."
At H:\PowerShell\WorkingArea\DSC\webApp\webApp.ps1:1 char:1
+ Configuration WebApp
+ ~~~~~~~~~~~~~~~~~~~~

Configuration WebApp
{
    
    # Import the module that defines custom resources
    Import-DscResource -ModuleName PSDesiredStateConfiguration
    Import-DscResource -ModuleName xWebAdministration
    Import-DscResource -ModuleName xNetworking
    Import-DscResource -ModuleName xSQLServer


    Node $AllNodes.Where($_.Role -contains "sqlServer").nodename
    {
    # Install a prerequisite Windows feature
        WindowsFeature "NET"
        {
            Ensure  = "Present"
            Name    = "NET-Framework-Core"
            Source  = $Node.winSource
        }
    
        xsqlServerSetup ($node.nodename)
        {
            DependsOn           = '[WindowsFeature]NET'
            SourcePath          = $Node.sqlSource
            SetupCredential     = $Node.InstallerServiceAccount
            InstanceName        = $Node.InstanceName
            Features            = $Node.Features
            SQLSysAdminAccounts = $Node.AdminAccount
            SQLSvcAccount       = $Node.InstallerServiceAccount
            InstallSharedDir    = $node.InstallSharedDir
            InstallSharedWOWDir = $Node.InstallSharedWOWDir
            InstanceDir         = $Node.InstanceDir
            InstallSQLDataDir   = $Node.InstallSQLDataDir
            SQLUserDBDir        = $Node.SQLUserDBDir
            SQLUserDBLogDir     = $Node.SQLUserDBLogDir
            SQLTempDBDir        = $Node.SQLTempDBDir
            SQLTempDBLogDir     = $Node.SQLTempDBLogDir
            SQLBackupDir        = $Node.SQLBackupDir
        }

        ## Add firewall exceptions for SQL Server but run SQL server setup first.
        xSqlServerFirewall ($Node.NodeName)
        {
            DependsOn           = ("[xSqlServerSetup]" + $Node.NodeName)
            SourcePath          = $Node.sqlSource
            InstanceName        = $Node.InstanceName
            Features            = $Node.Features
        }
        xSQLServerMemory ($Node.Nodename)
         {
             Ensure             = "Present"
             SQLInstanceName    = $Node.InstanceName
             DynamicAlloc       = $True
             DependsOn          = ("[xSqlServerSetup]" + $Node.NodeName)
         }
         xSQLServerMaxDop($Node.Nodename)
         {
             Ensure             = "Present"
             SQLInstanceName    = $Node.InstanceName
             DynamicAlloc       = $true
             DependsOn          = ("[xSqlServerSetup]" + $Node.NodeName)     
         }
        
    }

    Node $AllNodes.where($_.Role -contains "WebServer").NodeName
    { 
        # Install the IIS role
        WindowsFeature IIS
        {
            Ensure          = "Present"
            Name            = "Web-Server"
        }

        # Install the ASP .NET 4.5 role
        WindowsFeature AspNet45
        {
            Ensure          = "Present"
            Name            = "Web-Asp-Net45"
        }

        # Stop the default website
        xWebsite DefaultSite
        {
            Ensure          = "Present"
            Name            = "Default Web Site"
            State           = "Stopped"
            PhysicalPath    = "C:\inetpub\wwwroot"
            DependsOn       = "[WindowsFeature]IIS"
        }

        # Copy the website content
        File WebContent
        {
            Ensure          = "Present"
            SourcePath =    = $node.siteSource
            DestinationPath = $node.siteDestination
            Recurse         = $true
            Type            = "Directory"
            DependsOn       = "[WindowsFeature]AspNet45"
        }

        # Create the new Website with HTTP
        xWebsite NewWebsite
        {
            Ensure          = "Present"
            Name            = $Node.WebSiteName
            State           = "Started"
            PhysicalPath    = $node.siteDestination
            BindingInfo     = @(
                MSFT_xWebBindingInformation
                {
                    Protocol    = $Node.protocol
                    Port        = $Node.port
                }
            )
            DependsOn       = "[File]WebContent"
        }

        # Edit the hosts file
        xHostsFile hostsFile
        {
            Hostname = $Node.HostFileEntry
            IPAddress = $Node.HostFileIP
        }
    }    

}

WebApp -ConfigurationData .\webApp.psd1 -verbose
@{
    AllNodes = @(

        @{
            NodeName  = '*'
            winSource = '\\dscserver\Data\2012R2\sources\sxs'
            sqlSource = '\\dscserver\Data\SQL2014'

        },

        @{
            NodeName                    = 'DSCSQL'
            Role                        = 'sqlServer'
            InstanceName                = 'MSSQL'
            PSDscAllowPlainTextPassword = $true
            PSDscAllowDomainUser        = $true
            AdminAccount                = "domain\user"
            InstallSharedDir            = "C:\Program Files\Microsoft SQL Server"
            InstallSharedWOWDir         = "C:\Program Files (x86)\Microsoft SQL Server"
            InstanceDir                 = "C:\Program Files\Microsoft SQL Server"
            InstallSQLDataDir           = "C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Data"
            SQLUserDBDir                = "C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Data"
            SQLUserDBLogDir             = "C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Data"
            SQLTempDBDir                = "C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Data"
            SQLTempDBLogDir             = "C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Data"
            SQLBackupDir                = "C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Data"
        },

        @{
            NodeName        = 'DSCWEB'
            Role            = 'WebServer'
            WebsiteName     = 'mytestsite'
            SiteSource      = '\\dscserver\Data\mytestsite'
            SiteDestination = 'C:\inetpub\wwwroot\'
            HostFileEntry   = 'mytestsite.net'
            HostFileIP      = '127.0.0.1'
            Protocol        = 'HTTP'
            Port            = '8089'

        }
    );
}

March 10, 2017 at 4:33 pm

The problem is in the Node statements. If you use Intellisense to autocomplete things, it will add the parentheses for you but not the curly braces.

Node $AllNodes.Where($_.Role -contains "sqlServer").nodename

should be
Node $AllNodes.Where({$_.Role -contains "sqlServer"}).nodename

March 10, 2017 at 6:44 pm

Also – certain things that bite me once (like this one) I tend to remember the pain – and the fix – but if you have trouble remembering the syntax, remember that it's the same syntax as a "where-object", i.e. get-something | where-object {$_.name -like "Something*"}

March 15, 2017 at 6:35 am

Thanks for the help, much appreciated!