Allnodes.where isn't working for me!

Welcome Forums DSC (Desired State Configuration) Allnodes.where isn't working for me!

Viewing 6 reply threads
  • Author
    Posts
    • #20757
      Participant
      Topics: 23
      Replies: 48
      Points: 0
      Rank: Member

      Just to start, I wouldn't have gotten this far without the help of the Daves (plural) Dons and Jones's (also plural) of Powershell.org. So thanks much! I'm ready to put out my first somewhat useful DSC configuration, and I've hit a snag. I have composite resources down and working (they generate mofs without issue). But when I go to run it in my "dynamic master config file" (dynamic in that it's AD connected and uses a few "where" and "foreach") it goes through without error and without generating any MOFs. I'm kind of scratching my head. Here's my script:

      function GetAllServers {
          import-module ActiveDirectory
          Get-ADComputer -SearchBase "OU=DSCdev,DC=farnham,DC=contoso,DC=com" -Filter *
      }
      $AllServers = GetAllServers
      
      function Get-NodeEnvironment {
          [OutputType([string])]
          param (
              [Parameter(Mandatory)]
              [string] $DistinguishedName
          )
       
          switch -Wildcard ($DistinguishedName) {
              '*OU=Stage*' { return 'Stage' }
              '*OU=QA*'    { return 'QA' }
              '*OU=DEV*'   { return 'DEV' }
              default      { return 'Production' }
          }
      }
      
      function Get-NodeRole {
          [OutputType([string])]
          param (
              [Parameter(Mandatory)]
              [string] $DistinguishedName
          )
       
          $cn = ($DistinguishedName -split ',')[0]
       
          switch -Wildcard ($cn) {
              '*IIS*' { return 'WebServer' }
              '*DC*'  { return 'ADDS' }
              '*SQL*' { return 'SQL' }
              default { return 'Vanila' }
          }
      }
      
      # Gather AllNodes and add an environment variable to it based on OU name.
      $AllServerConfigData = @{
          AllNodes = @(
              foreach ($node in $AllServers) {
                  @{
                      NodeName        = $node.Name
                      NodeGUID        = $node.objectGUID
                      NodeEnvironment = Get-NodeEnvironment -DistinguishedName $node.DistinguishedName
                      NodeRole = Get-NodeRole -DistinguishedName $node.DistinguishedName
                  }
              }
          )
      }
      
      Configuration WindowsBackup {
          WindowsFeature WindowsSbackup 
          {
              Name = "Windows-Server-Backup"
              Ensure = "Present"
              IncludeAllSubFeature = "$True"
          }
      } 

      I tie together everything in the above with this (split on this page for legibility/highlighting)

      Configuration Everything 
      {
      Import-DscResource -Name rdsserver, myiispull, rfileserver
      Import-DscResource -ModuleName xsmbshare
          {Node $allnodes.where {$_.NodeRole -eq "WebServer"}.NodeGuid {
              MyIISPull AllWinFeatures {}
              }
          }
      
          {Node $allnodes.where {$_.NodeRole -eq "ADDS"}.NodeGuid {
              RdsServer TerminalServices {}
              }
          }
          {Node $allnodes.Where{$_.NodeRole -eq "SQL"}.NodeGuid {
              rFileServer WinSharesYay {}
              RdsServer TerminalServicesSQL{}
              }
          }
          {Node $allnodes.where{$_.NodeEnvironment -eq "Production"}.NodeGuid {
              WindowsBackup BackupProductionAlways {}
              }
          }          
      }
      
      Everything -ConfigurationData $AllServerConfigData 

      The above goes through, but no errors and no MOFs.

      I have tested the actual composites by running this (I run "PullDemo" instead of "Everything"), and it works / generates MOFs. So I'm fairly certain its not my composites.

       
      Configuration PullDemo {
      Import-DscResource -Name rdsserver, myiispull, rfileserver
      Import-dscResource -modulename xsmbshare
          Node $Allnodes.NodeGUID {
                      WindowsFeature IIS {
                          Ensure = 'Present'
                          Name = 'Web Server'
                      }
                      rdsserver ASP45 {}
                      rfileserver filesyay {}
                      WindowsBackup AlwaysBackupProd {}
          }
      }
      
      pulldemo -ConfigurationData $AllServerConfigData -outpath "C:\CieDSCCustom\WorkDir" 
    • #20758
      Member
      Topics: 9
      Replies: 2322
      Points: 0
      Rank: Member

      You've got some curly braces in strange places, and are missing parentheses in your calls to .Where(). Try this and see if it works better:

      Configuration Everything 
      {
          Import-DscResource -Name rdsserver, myiispull, rfileserver
          Import-DscResource -ModuleName xsmbshare
          
          Node $allnodes.where({$_.NodeRole -eq "WebServer"}).NodeGuid {
              MyIISPull AllWinFeatures {}
          }
       
          Node $allnodes.where({$_.NodeRole -eq "ADDS"}).NodeGuid {
              RdsServer TerminalServices {}
          }
      
          Node $allnodes.where({$_.NodeRole -eq "SQL"}).NodeGuid {
              rFileServer WinSharesYay {}
              RdsServer TerminalServicesSQL{}
          }
          
          Node $allnodes.where({$_.NodeEnvironment -eq "Production"}).NodeGuid {
              WindowsBackup BackupProductionAlways {}
          }          
      }
      
    • #20759
      Participant
      Topics: 23
      Replies: 48
      Points: 0
      Rank: Member

      Yar there be MOF's capn' hehe 🙂 I need to hit my head with a few powershell books and become a real scripter. The extra braces are from my math knowledge of 'BEDMAS' so I know everything needs to be closed... but which brackets/braces to use and where/how many sometimes falls flat on me! The MOFs look good, and now to make the minions listen! haha 🙂

    • #20762
      Participant
      Topics: 23
      Replies: 48
      Points: 0
      Rank: Member

      Spoke too soon! Closed and re opened powershell and now when I try to run this in a new session I"m given errors like this:

      PSDesiredStateConfiguration\Node : The term 'RdsServer\RdsServer' 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:86 char:5
      +     Node $allnodes.where({$_.NodeRole -eq "ADDS"}).NodeGuid {
      +     ~~~~
          + CategoryInfo          : ObjectNotFound: (RdsServer\RdsServer:String) [PSDesiredStateConfiguration\node], ParentContainsErrorRecordException
          + FullyQualifiedErrorId : CommandNotFoundException,PSDesiredStateConfiguration\node
       
      PSDesiredStateConfiguration\Node : The term 'rFileServer\rFileServer' 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:90 char:5
      +     Node $allnodes.where({$_.NodeRole -eq "SQL"}).NodeGuid {
      +     ~~~~
          + CategoryInfo          : ObjectNotFound: (rFileServer\rFileServer:String) [PSDesiredStateConfiguration\node], ParentContainsErrorRecordException
          + FullyQualifiedErrorId : CommandNotFoundException,PSDesiredStateConfiguration\node
       
      PSDesiredStateConfiguration\Node : The term 'rFileServer\rFileServer' 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:90 char:5
      +     Node $allnodes.where({$_.NodeRole -eq "SQL"}).NodeGuid {
      +     ~~~~
          + CategoryInfo          : ObjectNotFound: (rFileServer\rFileServer:String) [PSDesiredStateConfiguration\node], ParentContainsErrorRecordException
          + FullyQualifiedErrorId : CommandNotFoundException,PSDesiredStateConfiguration\node
       
      PSDesiredStateConfiguration\Node : The term 'rFileServer\rFileServer' 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:90 char:5
      +     Node $allnodes.where({$_.NodeRole -eq "SQL"}).NodeGuid {
      +     ~~~~
          + CategoryInfo          : ObjectNotFound: (rFileServer\rFileServer:String) [PSDesiredStateConfiguration\node], ParentContainsErrorRecordException
          + FullyQualifiedErrorId : CommandNotFoundException,PSDesiredStateConfiguration\node
       
      Errors occurred while processing configuration 'Everything'.
      At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psm1:2088 char:5
      +     throw $errorRecord
      +     ~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidOperation: (Everything:String) [], InvalidOperationException
          + FullyQualifiedErrorId : FailToProcessConfiguration
    • #20763
      Member
      Topics: 9
      Replies: 2322
      Points: 0
      Rank: Member

      I think that means Import-DscResource isn't finding your composite resources for some reason. Make sure the folder and file structure for the module that contains your composite resources is correct. (You should see them showing up when you run Get-DscResource at the command line.)

    • #20765
      Participant
      Topics: 23
      Replies: 48
      Points: 0
      Rank: Member

      Thank goodness for vmware snapshots. in my tiredness I failed to realize what I did.

      See, I've added a path to powershell's default module path so that my co workers aren't digging into programfiles or other places, that our stuff is "our stuff" and it's clear. I've noticed while copy-pasting some of the files out of the latest resource kit that the file names are gigantonormous and give errors, so to evade this I wanted to make instructions to expand things from zip file in the places they go, and I had this script I was writing to make it simple... yeah at this point not a good idea I think I borked it myself.

      anyway I've gone back to an older snapshot and it's looking okay. I'll have to figure it out at a later time that's not friday, for now I want results! 🙂

    • #20766
      Participant
      Topics: 23
      Replies: 48
      Points: 0
      Rank: Member

      And lo behold while I try to get results I find the problem...

      I copy the modules and their checksums to C:\Program Files\WindowsPowerShell\DscService\Modules so that the LCMs of targets can download modules.

      The problem happens after that? I'm using the latest resource package release (version 8). Confirmed this by deleting them and restarting powershell. This is the difference between my MOFs getting generated and the errors I spoke of before.

Viewing 6 reply threads
  • The topic ‘Allnodes.where isn't working for me!’ is closed to new replies.