Trying to get hash table working in DSC

I have DSC working with 2 nodes. Pull server and nodes are 2008R2. Simple mof, one Guid, IIS install works. Now I want to take it one step forward and use a hash table. The goal is to add and remove nodes from the hash table at will and leave the mof alone. Doing this in steps so I’ll want more out of it later but I’m brand new to PS so clearly there are some basic stumbling blocks. So I have this;

Configuration AllNodeIIS {

Node $AllNodes.where{$_.Role -eq “Web”}.NodeName
{
# Install the IIS role
WindowsFeature IIS
{
Ensure = “Present”
Name = “Web-Server”
}
}
}
AllNodeIIS -ConfigData $VariableNameHoldingConfigData -Verbose;
#My thought is this would create the mof and call the hash table. Then this is the hash table;

#hash table for all nodes
$AllNodeIIS =
@{
AllNodes = @(

    @{
        NodeName = "real node name"
        Role     = "Web"
    },


    @{
        NodeName = "real node name"
        Role     = "Web"
    }

  );

}
Without “AllNodeIIS -ConfigData $VariableNameHoldingConfigData -Verbose;” this would run and do nothing. A friend suggested I add this because I needed to invoke the config and I wanted to be able to see what was happening. After I added it I got the message;
PSDesiredStateConfiguration\Configuration : The term ‘PSDesiredStateConfiguration\Configuration’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included,
verify that the path is correct and try again.
At line:1 char:1

  • configuration AllNodeIIS {
  •   + CategoryInfo          : ObjectNotFound: (PSDesiredStateC...n\Configuration:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException 
    
    

I then ran PS C:\Windows\system32> Get-Module and got this;
ModuleType Version Name ExportedCommands


Script 1.0.0.0 ISE {Get-IseSnippet, Import-IseSnippet, New-IseSnippet}
Manifest 3.1.0.0 Microsoft.PowerShell.Management {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content…}
Manifest 3.0.0.0 Microsoft.PowerShell.Security {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl, Get-AuthenticodeSignature…}
Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object…}
Manifest 3.0.0.0 Microsoft.WSMan.Management {Connect-WSMan, Disable-WSManCredSSP, Disconnect-WSMan, Enable-WSManCredSSP…}
Manifest 3.0.2.0 PSDesiredStateConfiguration
Binary 1.0 PSDesiredStateConfiguration {Set-DscLocalConfigurationManager, Start-DscConfiguration, Configuration, Get-DscConfiguration…}

So it’s there, right. Lost right now. It’s taking me a long time to get nowhere. Help! Hopefully I’ve given you enough info to go by. Thanks in advance.

You’re close. Here’s some working demo code:

Configuration AllNodeIIS {

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

$AllNodeIIS =
@{
    AllNodes = @(

        @{
            NodeName = "real node name1"
            Role = "Web"
        },

        @{
            NodeName = "real node name2"
            Role = "Web"
        }

    );

}

AllNodeIIS -ConfigurationData $AllNodeIIS -Verbose;

You have to define the hashtable before the call to your configuration, and the parameter name is -ConfigurationData, not -ConfigData. (You were also using $VariableNameHoldingConfigData instead of $AllNodeIIS in the call to the configuration.)

Also, make sure you’re running the 64-bit version of powershell.exe. Based on that error you reported, I suspect you’re running a 32-bit version, and DSC doesn’t exist there.

Thanks. I’m going to give this a go.

Still getting this;
PSDesiredStateConfiguration\Configuration : The term ‘PSDesiredStateConfiguration\Configuration’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included,
verify that the path is correct and try again.
At line:1 char:1

  • Configuration AllNodeIIS {
  •   + CategoryInfo          : ObjectNotFound: (PSDesiredStateC...n\Configuration:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
    
    

Definitely using 64 bit. Anything else I can look at? I have to be missing something basic. Thanks!

Unless something has gone wrong with your PS installation, I’m not sure what would cause that. Try running these commands:

Get-Module -ListAvailable PSDesiredStateConfiguration

Get-Command -Module PSDesiredStateConfiguration

Here are the results I get from those commands on my computer (Windows 8.1 with the WMF 5.0 November Preview):

C:\Users\dlwya_000\Documents\GitHub> Get-Module -ListAvailable PSDesiredStateConfiguration


    Directory: C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   1.0        PSDesiredStateConfiguration         {Set-DscLocalConfigurationManager, Start-DscConfiguration,...


C:\Users\dlwya_000\Documents\GitHub> Get-Command -Module PSDesiredStateConfiguration

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Function        Configuration                                      1.0        PSDesiredStateConfiguration
Function        Find-DscResource                                   1.0        PSDesiredStateConfiguration
Function        Get-DscConfiguration                               1.0        PSDesiredStateConfiguration
Function        Get-DscConfigurationStatus                         1.0        PSDesiredStateConfiguration
Function        Get-DscLocalConfigurationManager                   1.0        PSDesiredStateConfiguration
Function        Get-DscResource                                    1.0        PSDesiredStateConfiguration
Function        New-DSCCheckSum                                    1.0        PSDesiredStateConfiguration
Function        Restore-DscConfiguration                           1.0        PSDesiredStateConfiguration
Function        Test-DscConfiguration                              1.0        PSDesiredStateConfiguration
Cmdlet          Compare-DscConfiguration                           1.0        PSDesiredStateConfiguration
Cmdlet          Publish-DscConfiguration                           1.0        PSDesiredStateConfiguration
Cmdlet          Set-DscLocalConfigurationManager                   1.0        PSDesiredStateConfiguration
Cmdlet          Start-DscConfiguration                             1.0        PSDesiredStateConfiguration
Cmdlet          Update-DscConfiguration                            1.0        PSDesiredStateConfiguration

Edit: Ignore all the HTML escape bits. That’s our forum software trying to be helpful (and failing.)

Thanks Dave. The first one returns this;
Windows PowerShell
Copyright © 2013 Microsoft Corporation. All rights reserved.

PS C:\Windows\system32\WindowsPowerShell\v1.0> Get-Module -ListAvailable PSDesiredStateConfiguration

Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version Name ExportedCommands


Manifest 3.0.2.0 PSDesiredStateConfiguration

Directory: C:\Windows\system32\WindowsPowerShell\v1.0\Modules\backup

ModuleType Version Name ExportedCommands


Manifest 3.0.2.0 PSDesiredStateConfiguration

Directory: C:\Windows\system32\WindowsPowerShell\v1.0\Modules

ModuleType Version Name ExportedCommands


Binary 1.0 PSDesiredStateConfiguration {Set-DscLocalConfigurationManager, Start-DscConfiguration,…

PS C:\Windows\system32\WindowsPowerShell\v1.0>

The second command returns nothing. Just goes back to the prompt. I’m starting to think I broke something in testing. I used your instructions to set this up (Thanks btw). I probably need to go back to some point and redo some things. What point do I need to go back to? Thanks. Going out to shovel 2 feet of snow. I’ll check back in a bit. Thanks!

PG

OK, you should remove or rename “C:\Program Files\WindowsPowerShell\Modules\PSDesiredStateConfiguration” and “C:\Windows\system32\WindowsPowerShell\v1.0\Modules\backup\PSDesiredStateConfiguration”; those are screwing you up. (And I have no idea why that “backup” location even exists or is on your PSModulePath.

Dave you rock. That was it. Now I get;
PS C:\Windows\system32> Get-Module -ListAvailable PSDesiredStateConfiguration

Directory: C:\Windows\system32\WindowsPowerShell\v1.0\Modules

ModuleType Version Name ExportedCommands


Binary 1.0 PSDesiredStateConfiguration {Set-DscLocalConfigurationManager, Start-DscConfiguration, Configuration, Get-DscConfiguration…}

PS C:\Windows\system32> Get-Command -Module PSDesiredStateConfiguration

CommandType Name ModuleName


Function Configuration PSDesiredStateConfiguration
Function Get-DscConfiguration PSDesiredStateConfiguration
Function Get-DscLocalConfigurationManager PSDesiredStateConfiguration
Function Get-DscResource PSDesiredStateConfiguration
Function New-DSCCheckSum PSDesiredStateConfiguration
Function Restore-DscConfiguration PSDesiredStateConfiguration
Function Test-DscConfiguration PSDesiredStateConfiguration
Cmdlet Set-DscLocalConfigurationManager PSDesiredStateConfiguration
Cmdlet Start-DscConfiguration

Also the original reason for my post, the configuration works. The mofs were created for the nodes listed in the hash. However I have another question related to this. My understanding is that I could have a ps1 file (top of the script) that points to a psd1 file (hash, holding the nodes) bottom of the script. That way any time I wanted to add or remove nodes I could just change the hash. Am I completely wrong? Is the one file the only way to do this? Again, thanks!