# Trying to get hash table working in DSC

**URL:** <https://forums.powershell.org/t/trying-to-get-hash-table-working-in-dsc/3669>\
**Category:** DSC\
**Created:** [January 26, 2015, 2:41am UTC](https://forums.powershell.org/t/trying-to-get-hash-table-working-in-dsc/3669 "2015-01-26T02:41:32Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![paul-gonzalez](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@paul-gonzalez](https://forums.powershell.org/u/paul-gonzalez)\
**Post date:** [January 26, 2015, 2:41am UTC](https://forums.powershell.org/t/trying-to-get-hash-table-working-in-dsc/3669/1 "2015-01-26T02:41:32Z")

</div>

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 {
- 

```auto
  + 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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [January 26, 2015, 2:46am UTC](https://forums.powershell.org/t/trying-to-get-hash-table-working-in-dsc/3669/2 "2015-01-26T02:46:04Z")

</div>

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.)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [January 26, 2015, 2:54am UTC](https://forums.powershell.org/t/trying-to-get-hash-table-working-in-dsc/3669/3 "2015-01-26T02:54:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![paul-gonzalez](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@paul-gonzalez](https://forums.powershell.org/u/paul-gonzalez)\
**Post date:** [January 26, 2015, 5:05am UTC](https://forums.powershell.org/t/trying-to-get-hash-table-working-in-dsc/3669/4 "2015-01-26T05:05:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paul-gonzalez](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@paul-gonzalez](https://forums.powershell.org/u/paul-gonzalez)\
**Post date:** [January 26, 2015, 5:35am UTC](https://forums.powershell.org/t/trying-to-get-hash-table-working-in-dsc/3669/5 "2015-01-26T05:35:25Z")

</div>

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 {
- 

```auto
  + 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!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [January 26, 2015, 8:35am UTC](https://forums.powershell.org/t/trying-to-get-hash-table-working-in-dsc/3669/6 "2015-01-26T08:35:16Z")

</div>

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.)

---

<div class="post-metadata">

**Author:** ![paul-gonzalez1](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/paul-gonzalez1/32/808_2.png) [@paul-gonzalez1](https://forums.powershell.org/u/paul-gonzalez1)\
**Post date:** [January 27, 2015, 4:09am UTC](https://forums.powershell.org/t/trying-to-get-hash-table-working-in-dsc/3669/7 "2015-01-27T04:09:29Z")

</div>

Thanks Dave. The first one returns this;  
Windows PowerShell  
Copyright (C) 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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [January 27, 2015, 4:11am UTC](https://forums.powershell.org/t/trying-to-get-hash-table-working-in-dsc/3669/8 "2015-01-27T04:11:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![paul-gonzalez1](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/paul-gonzalez1/32/808_2.png) [@paul-gonzalez1](https://forums.powershell.org/u/paul-gonzalez1)\
**Post date:** [January 27, 2015, 9:11am UTC](https://forums.powershell.org/t/trying-to-get-hash-table-working-in-dsc/3669/9 "2015-01-27T09:11:51Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 9:17pm UTC](https://forums.powershell.org/t/trying-to-get-hash-table-working-in-dsc/3669/10 "2024-05-16T21:17:24Z")

</div>

Closed on May 16, 2024, 9:17pm UTC


