Author Posts

December 1, 2016 at 10:00 am

Hi, I wanted to know what are possible parameter types in DSC Resources?

We need an array of hashtables – [hashtable[]] – and it is not possible because the MOF transfers it to simple dictionary/hashtable...

Why there is this MOF used in the present times, when there are better serialization possibilities nowadays 🙁

December 6, 2016 at 9:00 pm

MOF is an industry standard format for this kind of thing. And regardless of the "why," it's what we have. Passing complex objects is perhaps a bit outside what the design vision was, but can you give me an example of the data involved? It'd help me understand better.

December 9, 2016 at 10:13 am

Thanks for explanation, the structure is pasted bellow. The number of users and groups changes per server instance, and we want to use one general DSC script for all the servers. That's why we don't declare DSC resource for one user or one group.

[DscResource()]
class CreateAGSUsersAndRoles
{
    [DscProperty(Key)]
    [string]$Server
    [DscProperty(Mandatory)]
    [hashtable[]]$Users
    [DscProperty(Mandatory)]
    [hashtable[]]$Roles

    [void] Set()
    {

        foreach ($CurrentUser in ($this.Users)) {

            Create-AGSUser -Server $this.Server -UserName $CurrentUser.name -Password $CurrentUser.password -FullName $CurrentUser.fullname -Email $CurrentUser.email -Description $CurrentUser.description
        }

        foreach ($CurrentRole in ($this.Roles)) {
        
            Create-AGSRole -Server $this.Server -RoleName $CurrentRole.name -Description $CurrentRole.description
            Add-AGSUserToAGSRole -Server $this.Server -Role $CurrentRole.name -Users $CurrentRole.users
        }
    }

    [bool] Test()
    {
        return $false
    }

    [CreateAGSUsersAndRoles] Get()
    {
        return $this
    }
}

$cd = @{
     AllNodes = @(
        @{
           #...

        }
          @{

            Server = 'http://server:6080'
            #AGSPrivileges
            Users = @(
                        @{ name="user1"
                           password="user1"
                           fullname="user1"
                           email="dummyUser1@example.com"
                           description="Used to secure AGS dummy service"
                         }
                        @{ name="user2"
                           password="user2"
                           fullname="user2"
                           email="dummyUser2@example.com"
                           description="Used to secure AGS dummy service"
                         }
                      )
            Roles = @(
                        @{ name="gns_soe2"
                           privilege="ACCESS"
                           description=""
                           users="user1"
                        }
                        @{ name="secure_services2"
                           privilege="ACCESS"
                           description=""
                           users="user1,user2"
                         }
                     )
            }
       )
 }

We found a workaround to pass the hashtable arrays as JSON string and we then deserialize it in the DSC Resource Set Method. But that's ugly.

Thx for ideas