Import-PowerShellDataFile not returning a hashtable of ConfigurationData

This topic contains 2 replies, has 2 voices, and was last updated by  Tex 5 days, 17 hours ago.

  • Author
    Posts
  • #87469

    Tex
    Participant

    I'm assuming I'm doing something wrong here. I have the following (stripped down) ConfigurationData.psd1 file as follows:

    @{
        AllNodes = @(
                         @{
                             NodeName = "*"
                             PSDscAllowPlainTextPassword = $true
                             PSDscAllowDomainUser = $true
                         }
                         @{
                             NodeName = "test"
                             Role = "Blah"
                         }
                     )
    }
    

    When I run:

    $ConfigurationData = Import-PowerShellDataFile -Path C:\Temp\ConfigurationData.psd1
    

    My understanding is that $ConfigurationData should be a hashtable, but it is returning as an array:

    PS C:\> $ConfigurationData
    
    Name                           Value                                                                                                                                                                                                                                                                         
    ----                           -----                                                                                                                                                                                                                                                                         
    AllNodes                       {System.Collections.Hashtable, System.Collections.Hashtable}                                                                                                                                                                                                                  
    
    PS C:\> $ConfigurationData.GetType()
    
    IsPublic IsSerial Name                                     BaseType                                                                                                                                                                                                                                          
    -------- -------- ----                                     --------                                                                                                                                                                                                                                          
    True     True     Object[]                                 System.Array                                                                                                                                                                                                                                      
    
    

    The few examples of I can find, my ConfigurationData.psd1 is correct. I did read a note on here about not using commas between each hash element – contrary to the MS examples.

    I am assuming this is the problem, because when I compile my DSC with

    -ConfigurationData $ConfigurationData

    , I get the error:

    Cannot process argument transformation on parameter 'ConfigurationData'. Cannot convert the "System.Object[]" value of type "System.Object[]" to type "System.Collections.Hashtable".
    

    To add to my confusion further, if I set

    -ConfigurationData C:\Temp\ConfigurationData.psd1

    , the DSC compiles without issue, suggesting the problem is not in the ConfigurationData.psd1 file.

    Assuming I'm not being an idiot, I wonder if there is a bug in Import-PowerShellDataFile. Therefore, this is running on Windows Server 2012 R2, with PS version 5.1.14409.1005.

    Any pointer will be gratefully received.

    TIA

  • #87623

    gael
    Participant

    Copy pasting your code (mostly) give me the following:

    PS C:\Users\Gael> cd C:\src\test
    
    PS C:\src\test> $ConfigurationData = Import-PowerShellDataFile -Path C:\src\test\test.psd1
    
    PS C:\src\test> $ConfigurationData.GetType()
    
    IsPublic IsSerial Name                                     BaseType            
    -------- -------- ----                                     --------            
    True     True     Hashtable                                System.Object       
    
    
    
    PS C:\src\test> $PSVersionTable
    
    Name                           Value                                           
    ----                           -----                                           
    PSVersion                      5.1.17046.1000                                  
    PSEdition                      Desktop                                         
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                         
    BuildVersion                   10.0.17046.1000                                 
    CLRVersion                     4.0.30319.42000                                 
    WSManStackVersion              3.0                                             
    PSRemotingProtocolVersion      2.3                                             
    SerializationVersion           1.1.0.1                                         
    
    
    
    PS C:\src\test> 
    

    I'll try on a server tomorrow, but you should try somewhere else... that's weird.

  • #87905

    Tex
    Participant

    Well, you know what they say, never assume! I was being an idiot.

    There was a pending reboot after I manually updated the box.

    It works fine now:

    PS C:\> $configData = Import-PowerShellDataFile -path C:\Temp\ConfigurationData.psd1
    
    $configData.GetType()
    
    IsPublic IsSerial Name                                     BaseType                                                                                                                                                                                                                                          
    -------- -------- ----                                     --------                                                                                                                                                                                                                                          
    True     True     Hashtable                                System.Object                                                                                                                                                                                                                                     
    
    PS C:\> $PSVersionTable
    
    Name                           Value                                                                                                                                                                                                                                                                         
    ----                           -----                                                                                                                                                                                                                                                                         
    PSVersion                      5.1.14409.1005                                                                                                                                                                                                                                                                
    PSEdition                      Desktop                                                                                                                                                                                                                                                                       
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                                                                                                                                       
    BuildVersion                   10.0.14409.1005                                                                                                                                                                                                                                                               
    CLRVersion                     4.0.30319.42000                                                                                                                                                                                                                                                               
    WSManStackVersion              3.0                                                                                                                                                                                                                                                                           
    PSRemotingProtocolVersion      2.3                                                                                                                                                                                                                                                                           
    SerializationVersion           1.1.0.1  
    

    Thank you and sorry for being an idiot.

You must be logged in to reply to this topic.