Azure Automation DSC – When using Start-AzAutomationDscCompilationJob param cred

Welcome Forums DSC (Desired State Configuration) Azure Automation DSC – When using Start-AzAutomationDscCompilationJob param cred

Viewing 1 reply thread
  • Author
    Posts
    • #221421
      Participant
      Topics: 30
      Replies: 69
      Points: 174
      Rank: Participant

      I have imported a DSC script successfully that has one parameter Credential. When I try and run the compilation to create a mof file (Start-AzAutomationDscCompilationJob), I don’t know how to -parameter parameter to use this credential. I created and tested the script and mof on the VM I am trying to apply it to and it works. If I use Import-AzAutomationDscNodeConfiguration to upload the mof file, it works. I just want to know how to use Start-AzAutomationDscCompilationJob with a parameter of credential. I need the credential for logging into a sql db on an application server.

      $pwss = (ConvertTo-SecureString $pw -AsPlainText -Force)
      $creds = New-Object System.Management.Automation.PSCredential($username, $pwss)
      $Parmeters = @{“Credential”= $creds}
      $stCfComParams = @{
          ConfigurationName = $ConfigurationName
          Parameters = $Parmeters
          ConfigurationData = $cfgData 
          ResourceGroupName = $ResourceGroupName 
          AutomationAccountName = $AAAName
      }
      
      $CompilationJob = Start-AzAutomationDscCompilationJob @stCfComParams
      
      Configuration DSC_Deploy
      {
      
          param
          (
              [Parameter()]
              [ValidateNotNull()]
              [PSCredential]$Credential
          )
      
          $CredUser = $Credential.UserName
          $CredPass = $Credential.GetNetworkCredential().Password
      
          Import-DscResource -ModuleName ‘PSDesiredStateConfiguration’
      
          Node $AllNodes.Where{$_.Property -eq “Yes”}.NodeName
          {
              Script ScriptDBBackup
              {
                  SetScript = {
      
      $query_backup = @’
                      SELECT 
      
      ‘@
                      $backupList = Invoke-Sqlcmd -Database $BcsDbName -Username $Using:CredUser -Password $Using:CredPass -Query $query_backup 
                  }
                  TestScript = {
      
                      if (  -not [string]::IsNullOrEmpty($TasksServiceName) ) {
                      $ServObj = Get-Service -Name $TasksServiceName
                          if ( $ServObj.Status -eq ‘Stopped’ ) {
                              Write-Verbose -Message “The service $TasksServiceName has stopped.”
                              return $false
                              ##########  AFTER TESING CHANGE TO FALSE
                          }else {
                              Write-Verbose -Message ‘Service $TasksServiceName is not stopped.’
                              $ServObj | Stop-Service -PassThru | foreach {
                                  if ( $_.Status -eq ‘stopped’ ) { 
                                      Write-Verbose -Message “The service $TasksServiceName has stopped.”
                                      return $false
                                  } else {
                                      Write-Verbose -Message ‘Service not stopped.’
                                      return $true
                                  }
                              }
                          }
                      }else {
                          Write-Verbose -Message ‘The variables not populated.’
                          return $true
                      }
                  }
                  GetScript = {
                  }
              }
          }
      }
      
      $username = ‘anadm8in’
      $pw = ‘@password123’
      $pwss = (ConvertTo-SecureString $pw -AsPlainText -Force)
      $creds = New-Object System.Management.Automation.PSCredential($username, $pwss)
      DSC_Deploy  -Credential $creds -ConfigurationData $cfgData -OutputPath $outP
      
      • This topic was modified 3 months, 3 weeks ago by i255d.
    • #225993
      Participant
      Topics: 30
      Replies: 69
      Points: 174
      Rank: Participant

      Anyone?

Viewing 1 reply thread
  • The topic ‘Azure Automation DSC – When using Start-AzAutomationDscCompilationJob param cred’ is closed to new replies.