PowerShell version: 5
I've uploaded a DSC ps1 file in a zip to Azure storage using the command:
publish-azurermvmdscconfiguration
With the appropriate parameters and arguments. Then I enter:
Set-AzureRmVmDSCExtension -ResourceGroupName Pollers -VmName <VmName> -ArchiveBlobName Run-DSCPython.zip -ArchiveStorageAccountName <storageAccountName> -Version 2.2 -Verbose
And I get the following (generally opaque) error message in PowerShell:
Set-AzureRmVmDSCExtension : The pipeline has been stopped.
At line:1 char:1
+ Set-AzureRmVmDSCExtension -ResourceGroupName Pollers -VmName Download ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Set-AzureRmVMDscExtension], PipelineStoppedException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.Extension.DSC.SetAzureVMDscExtensionCommand
Set-AzureRmVmDSCExtension : Long running operation failed with status 'Failed'.
At line:1 char:1
+ Set-AzureRmVmDSCExtension -ResourceGroupName Pollers -VmName Download ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidResult: (:) [Set-AzureRmVMDscExtension], CloudException
+ FullyQualifiedErrorId : InvalidResult,Microsoft.Azure.Commands.Compute.Extension.DSC.SetAzureVMDscExtensionCommand
In the Azure Portal though, I dig up a more detailed log, it's very long so I'll post here only the part I believe is connected to the error itself:
[ERROR] An error occurred while executing script or module 'Run-DSCPython':
The specified module 'Run-DSCPython' was not loaded because no valid module file
was found in any module directory.
Any idea what I need here? What module is it looking for?
While not exactly an answer to your question, I would propose you compile mofs in Azure Automation and register your VM's as nodes to Azure Automation, the process is a bit lengthy to write out here, I'll write a short guide:
# You can compile mof on your own PC and import, or compile in Azure Automation (preferred way)
<#
Import-AzureRmAutomationDscNodeConfiguration -Path "C:\localhost.mof" -ConfigurationName $configurationName `
-ResourceGroupName $ResourceGroupName -AutomationAccountName $AutomationAccountName -Force
#>
$AutomationAccountName = "Automation"
$ResourceGroupName = "Azure"
$Location = "West Europe"
$VnetName = "VNet"
$configurationName = "Configuration-1"
$credName = "Name of credential asset in Azure Automation"
$nodeName = "localhost"
$StorageAccountName = "something"
# Import Configuration
$sourcePath = "C:\DSC.ps1"
Import-AzureRmAutomationDscConfiguration -SourcePath $sourcePath `
-ResourceGroupName $ResourceGroupName -AutomationAccountName $AutomationAccountName -Published -Force
# Compile mof
$ConfigurationData = @{
AllNodes = @(
@{
NodeName = $nodeName
PSDscAllowPlainTextPassword = $true
RebootNodeIfNeeded = $true
DebugMode = "All"
}
)
}
$Parameters = @{
"storageAccountName" = $storageAccountName
"nodeName" = $nodeName
"credential" = $credName
}
Start-AzureRmAutomationDscCompilationJob -ResourceGroupName $ResourceGroupName -AutomationAccountName $AutomationAccountName `
-ConfigurationName $configurationName -Parameters $Parameters -ConfigurationData $ConfigurationData
# Register VM and apply mof
$VmName = "VM-Name";
Register-AzureRmAutomationDscNode -AutomationAccountName $AutomationAccountName -AzureVMName $VmName `
-ResourceGroupName $ResourceGroupName -NodeConfigurationName "$configurationName.localhost"
Edit: forgot to tell you the reasoning, I've wasted 2-3 weeks trying to make DSC extension to work RELIABLY. I failed miserably, Azure Automation on the other hand was far more reliable, although really tricky at the beginning.