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.
[pre]
$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
[/pre]