Failure when processing extension 'Microsoft.Powershell.DSC' - powershell

I am attempting to deploy a Azure Resource Template to a brand new Windows Server VM on Azure which includes a Microsoft.Powershell.DSC resource to the VM.
The DSC configuration file has been pushed to public accessible Azure Storage Blob container which I have verified can be downloaded from a browser accessing the URL.
After successfully deploying a new VM I added an extension sub-resource to execute the DSC configuration file stored in the Azure blob container mentioned above.
I cannot figure out why it is failing.
I execute the deployment using this command:
New-AzureRmResourceGroupDeployment `
-Name $resourceDeploymentName `
-ResourceGroupName $rscrcGrpName `
-TemplateFile $templatePath `
-TemplateParameterFile $parameterPath `
-Verbose
Here is the error:
New-AzureRmResourceGroupDeployment : 3:56:46 PM - Resource Microsoft.Compute/virtualMachines 'DC1' failed with message '{
"status": "Failed",
"error": {
"code": "ResourceDeploymentFailure",
"message": "The resource operation completed with terminal provisioning state 'Failed'.",
"details": [
{
"code": "VMExtensionProvisioningError",
"message": "VM has reported a failure when processing extension 'Microsoft.Powershell.DSC'. Error message: \"The DSC Extension failed to install:
Error unpacking 'DomainController-DSC.ps1'; verify this is a valid ZIP package.\nError details: Exception calling \"ExtractToDirectory\" with \"2\"
argument(s): \"End of Central Directory record could not be found.\".\r\nMore information about the failure can be found in the logs located under
'C:\\WindowsAzure\\Logs\\Plugins\\Microsoft.Powershell.DSC\\2.20.0.0' on the VM.\r\nTo retry install, please remove the extension from the VM first. \"."
}
]
}
}'
At line:1 char:1
+ New-AzureRmResourceGroupDeployment `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet
New-AzureRmResourceGroupDeployment : 3:56:46 PM - VM has reported a failure when processing extension 'Microsoft.Powershell.DSC'. Error message: "The DSC
Extension failed to install: Error unpacking 'DomainController-DSC.ps1'; verify this is a valid ZIP package.
Error details: Exception calling "ExtractToDirectory" with "2" argument(s): "End of Central Directory record could not be found.".
More information about the failure can be found in the logs located under 'C:\WindowsAzure\Logs\Plugins\Microsoft.Powershell.DSC\2.20.0.0' on the VM.
To retry install, please remove the extension from the VM first. ".
At line:1 char:1
+ New-AzureRmResourceGroupDeployment `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet
New-AzureRmResourceGroupDeployment : 3:56:46 PM - Template output evaluation skipped: at least one resource deployment operation failed. Please list
deployment operations for details. Please see https://aka.ms/arm-debug for usage details.
At line:1 char:1
+ New-AzureRmResourceGroupDeployment `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet
New-AzureRmResourceGroupDeployment : 3:56:46 PM - Template output evaluation skipped: at least one resource deployment operation failed. Please list
deployment operations for details. Please see https://aka.ms/arm-debug for usage details.
At line:1 char:1
+ New-AzureRmResourceGroupDeployment `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet
Here is the VM Resource definition:
{
"name": "[parameters('virtualMachineName')]",
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2015-06-15",
"location": "[parameters('location')]",
"tags": {
"displayName": "vm-DC1"
},
"dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]",
"[concat('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]",
"[concat('Microsoft.Storage/storageAccounts/', parameters('diagnosticsStorageAccountName'))]"
],
"properties": {
"osProfile": {
"computerName": "[parameters('virtualMachineName')]",
"adminUsername": "[parameters('vmAdminUsername')]",
"adminPassword": "[parameters('vmAdminPassword')]",
"windowsConfiguration": {
"provisionVmAgent": "true"
}
},
"hardwareProfile": {
"vmSize": "[parameters('virtualMachineSize')]"
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2012-R2-Datacenter",
"version": "latest"
},
"osDisk": {
"name": "[parameters('virtualMachineName')]",
"vhd": {
"uri": "[concat(concat(reference(resourceId(resourceGroup().name, 'Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2015-06-15').primaryEndpoints['blob'], 'vhds/'), parameters('virtualMachineName'), '2016812162929.vhd')]"
},
"createOption": "fromImage"
},
"dataDisks": [ ]
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaceName'))]"
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true,
"storageUri": "[reference(resourceId(resourceGroup().name, 'Microsoft.Storage/storageAccounts', parameters('diagnosticsStorageAccountName')), '2015-06-15').primaryEndpoints['blob']]"
}
}
},
"resources": [
{
"name": "Microsoft.Powershell.DSC",
"type": "extensions",
"location": "[parameters('location')]",
"apiVersion": "2015-06-15",
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachineName'))]"
],
"tags": {
"displayName": "dsc-DomainController"
},
"properties": {
"publisher": "Microsoft.Powershell",
"type": "DSC",
"typeHandlerVersion": "2.9",
"autoUpgradeMinorVersion": true,
"forceUpdateTag": "1.0",
"settings": {
"configuration": {
"url": "https://armstore0.blob.core.windows.net/dsc/DomainController-DSC.ps1.zip",
"script": "DomainController-DSC.ps1",
"function": "FileResourceDemo"
},
"configurationArguments": {
"nodeName": "[parameters('virtualMachineName')]"
}
}
}
}
]
}

It could be some network glitch. Have you tried deploying the template again?

Related

update/create TFS Server variable group using REST API with powershell gives object reference not set

Allright i have been fiddling with this for a few hours now and i can't seem to find any resources online or solve the issue.
Looking at the api documentation at https://learn.microsoft.com/en-us/rest/api/azure/devops/distributedtask/variablegroups/get?view=azure-devops-rest-6.0
I can get info regarding the variable group that i created as a test:
$invRestMethParams = #{
Uri = "https://xxx.xxx.nl/tfs/DefaultCollection/$($project)/_apis/distributedtask/variablegroups/242/?api-version=6.0-preview.2"
Method = 'GET'
ContentType = 'application/json'
}
Invoke-RestMethod #invRestMethParams -UseDefaultCredentials
I then convert the result to json to get the required values for the PUT or POST to update or create:
{
"variables": {
"check": {
"value": "value"
}
},
"id": 242,
"type": "Vsts",
"name": "TestUpdate",
"description": "",
"isShared": false,
"variableGroupProjectReferences": [
{
"projectReference": "#{id=0add8cd8-0fc8-4aca-8eb4-164cd8d09c9d; name=AutoUpdateVariableGroups}",
"name": "TestUpdate",
"description": ""
}
]
}
The documentation states the update url is:
PUT https://{instance}/{collection}/_apis/distributedtask/variablegroups/{groupId}?api-version=6.0-preview.2
With request body having the above json values (without the ID as this is in the URI). So my update json becomes:
$body = #"
{
"variables": {
"checkupdated": {
"value": "valueupdated"
}
},
"type": "Vsts",
"name": "TestUpdate",
"description": "",
"isShared": false,
"variableGroupProjectReferences": [
{
"projectReference": "#{id=0add8cd8-0fc8-4aca-8eb4-164cd8d09c9d; name=AutoUpdateVariableGroups}",
"name": "TestUpdate",
"description": ""
}
]
}
"#
i convert it from json to see if its valid (no errors).
and use it in my PUT request:
$invRestMethParams = #{
Uri = "https://xxx.xxx.nl/tfs/DefaultCollection/_apis/distributedtask/variablegroups/242/?&api-version=6.0-preview.2"
Method = 'PUT'
ContentType = 'application/json'
Body = $body
}
Invoke-RestMethod #invRestMethParams -UseDefaultCredentials
The error i receive is:
Invoke-RestMethod : {"$id":"1","innerException":null,"message":"Object reference not set to an instance of an object.","typeName":"System.NullReferenceException, mscorlib","typeKey":"NullReferenceException","errorCode":0,"eventId":0}
At line:32 char:1
+ Invoke-RestMethod #invRestMethParams -UseDefaultCredentials
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Not sure how to troubleshoot this, does anyone know how to fix this issue? seems i am forgetting a value but im kinda lost as to what is the issue here.
From your script, it seems that it has issue with your request body.
In projectReference field, you need to use , to replace the ; and you need to modify the format.
"projectReference": {"id":"projectID", "name":"projectname"},
Refer to my sample:
$JSON = #"
{
"variables": {
"checkupdate": {
"value": "vaslueupdate"
}
},
"type": "Vsts",
"name": "AA",
"description": "",
"isShared": false,
"variableGroupProjectReferences": [
{
"projectReference": {"id":"108e4d7c-0bf3-4940-80da-4793f83def92", "name":"kevin1012"},
"name": "AA",
"description": ""
}
]
}
"#

Getting HTTP Status Code: BadRequest when creating Azure Data Factory Trigger using PowerShell with AzureRm module

I am deploying Azure ADF trigger using PowerShell, all triggers deploying successfully except one trigger. I am getting the following error
[ERROR] Set-AzureRmDataFactoryV2Trigger : HTTP Status Code: BadRequest
[ERROR] Error Code: BadRequest
[ERROR] Error Message: The document creation or update failed because of invalid
[ERROR] reference 'pipeline1'
[ERROR] Request Id: 895u9iuy-4j34-227f-63d3-948jd8djw86e
[ERROR] Timestamp (Utc):07/13/2020 16:52:28
[ERROR] At C:\Users\user1\source\repos\MyProject\PowerShell\Deploy-AdFTr
[ERROR] iggersWithDLS.ps1:290 char:21
[ERROR] + ... Set-AzureRmDataFactoryV2Trigger -ResourceGroupName $stora ...
[ERROR] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ERROR] + CategoryInfo : CloseError: (:) [Set-AzureRmDataFactoryV2Trigger
[ERROR] ], CloudException
[ERROR] + FullyQualifiedErrorId : Microsoft.Azure.Commands.DataFactoryV2.SetAzureD
[ERROR] ataFactoryTriggerCommand
[ERROR]
My PowerShell code is below.
$isTriggerExist = Get-AzureRmDataFactoryV2Trigger -ResourceGroupName $storageAccountRG -DataFactoryName $dataFactoryName -TriggerName $triggerObject.Name -ErrorAction:SilentlyContinue
if($isTriggerExist -eq $null)
{
Set-AzureRmDataFactoryV2Trigger -ResourceGroupName $storageAccountRG -DataFactoryName $dataFactoryName -Name $triggerObject.Name -DefinitionFile $file -Force
if($runTimeState[$g] -eq "Started")
{
Start-AzureRmDataFactoryV2Trigger -ResourceGroupName $storageAccountRG -DataFactoryName $dataFactoryName -TriggerName $triggerObject.name -Force
}
}
I am sharing the trigger's JSON code.
{
"name": "trg_pipline1",
"properties": {
"annotations": [],
"runtimeState": "Started",
"pipelines": [
{
"pipelineReference": {
"referenceName": "pipeline1",
"type": "PipelineReference"
}
}
],
"type": "ScheduleTrigger",
"typeProperties": {
"recurrence": {
"frequency": "week",
"interval": 1,
"startTime": "2019-10-10T00:00:00Z",
"endTime": "2022-12-14T01:00:00Z",
"timeZone": "UTC",
"schedule": {
"hours": [
11,
13,
15,
17,
19,
21,
23
],
"weekDays": [
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday"
]
}
}
}
}
}
This error looks similar to this.
Could you please ensure that pipeline1 is deployed completely before you deploy trg_pipline1?
Also, can you verify if the steps given here are followed to create the Trigger? (Try removing "runtimeState": "Started")

Cannot pass an array type parameter in ARM template via Powershell

I have an ARM Template with the following parameters:
"parameters": {
"projectName": {
"type": "string",
"metadata": {
"description": "Name of the project"
}
},
"environmentName": {
"type": "string",
"defaultValue": "testing",
"metadata": {
"description": "Name/Type of the environment"
}
},
"vmResourceGroupName": {
"type": "string",
"metadata": {
"description": "Resource Group in which VMs wil be deployed"
}
},
"vmName": {
"type": "string",
"metadata": {
"description": "Name of the Virtual Machine"
}
},
"vmIPAddress": {
"type": "string",
"metadata": {
"description": "IP Address of the Virtual Machine"
}
},
"osDiskVhdUri": {
"type": "string",
"metadata": {
"description": "Uri of the existing VHD in ARM standard or premium storage"
}
},
"dataDiskVhdUri": {
"type": "array",
"metadata": {
"description": "Uri of the existing VHD in ARM standard or premium storage"
}
},
"vmSize": {
"type": "string",
"metadata": {
"description": "Size of the Virtual Machine"
}
},
"osType": {
"type": "string",
"allowedValues": [
"Windows",
"Linux"
],
"metadata": {
"description": "OS of the VM - Typically Windows or Linux"
}
},
"ManagedDisk": {
"type": "string",
"allowedValues": [
"Yes",
"No"
],
"metadata": {
"description": "Yes for Managed Disks, No for VHDs"
}
}
As evident, $dataDiskVHDURI is of type:array and I am trying to deploy the template using -TemplateParameterObject with New-AzureRMresourceGroupDeployment cmdlet in Powershell using the following code:
{
$vmWithDDTemplate = 'azuredeploy.json'
$vmWithoutDDTemplate = 'azuredeploy-withoutdd.json'
$dataDiskVhdUri = New-Object -TypeName System.Collections.ArrayList
$dataDiskVhdUri.Add("$VM.dataDiskVhduri")
#Creating VM param object
$VMTemplateObject = #{"projectname" = $projectName; `
"environmentname" = $environmentName; `
"vmResourceGroupName" = $vmResourceGroupName; `
"vmName" = $VM.vmName; `
"vmIPAddress" = $VM.vmIPAddress; `
"osDiskVhdUri" = $VM.osDiskVhdUri; `
"dataDiskVhdUri" = ,$dataDiskVhdUri; `
"vmSize" = $VM.vmSize; `
"osType" = $VM.osType; `
"ManagedDisk" = $VM.ManagedDisk
}
#$VMTemplateObject
# Checking if VM contains a data disk
if($VM.dataDiskVhdUri -ne $null)
{
Write Output "$VM contains data disk"
New-AzureRmResourceGroupDeployment -Name ('vmwithdd' + '-' + ((Get-Date).ToUniversalTime()).ToString('MMdd-HHmm')) `
-ResourceGroupName $ResourceGroupName `
-TemplateParameterObject $VMTemplateObject `
-TemplateFile $vmWithDDTemplate `
-Force -Verbose -ErrorVariable ErrorMessages `
-ErrorAction Stop -DefaultProfile $azureCred
}
else
{
Write-output '$VM does not contain data disk'
}
}
However, I get the following error every time:
Microsoft.PowerShell.Utility\Write-Error : 4:46:14 PM - Error:
Code=InvalidTemplate; Message=Deployment template validation failed:
'The provided value for the template parameter 'dataDiskVhdUri' at
line '44' and column '27' is not valid.'. At Create-Environment:73
char:73
+
+ CategoryInfo : NotSpecified: (:) [Write-Error], RemoteException
+ FullyQualifiedErrorId : System.Management.Automation.RemoteException,Microsoft.PowerShell.Commands.WriteErrorCommand
+ PSComputerName : [localhost]
Does anyone know how to resolve this?
Not sure, but maybe feeding it with an ArrayList object wrapped in an array by use of the preceeding , is not what it wants. If i lookup examples, i see only single values added there like "dataDiskVhdUri" = $VM.dataDiskVhduri;
Try this:
$OptionalParameters = New-Object -TypeName Hashtable
$OptionalParameters.Add("aParam", #(1,2,3))
New-AzureRmResourceGroupDeployment -ResourceGroupName $ResourceGroupName `
-TemplateFile azuredeply.json `
#OptionalParameters
With:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"aParam": {
"type": "array"
}
},
"variables": { },
"resources": [ ],
"outputs": {
"dump": {
"type": "array",
"value": "[parameters('aParam')]"
}
}
}

Azure/IoT - "HTTP request body must not be empty" on build.ps1 (ExtendedCode 51016)

When we run our Microsoft Connected Factory build (via build.ps1) for Microsoft Azure, we run into the error below.
FullyQualifiedErrorId:
"Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet".
The job was running previously, but suddenly started to fail today and there are no operational- or build-related changes of which we are aware.
Has anyone seen this error before? If so, what was the resolution?
The public cloud world is new to me, so forgive me if any of the above terminology is incorrectly used.
Any help is greatly appreciated.
Thanks in advance!
17:52:44 New-AzureRmResourceGroupDeployment : 5:52:44 PM - Resource Microsoft.Web/certificates 'mycertificatename' failed with
17:52:44 message '{
17:52:44 "Code": "BadRequest",
17:52:44 "Message": "HTTP request body must not be empty.",
17:52:44 "Target": null,
17:52:44 "Details": [
17:52:44 {
17:52:44 "Message": "HTTP request body must not be empty."
17:52:44 },
17:52:44 {
17:52:44 "Code": "BadRequest"
17:52:44 },
17:52:44 {
17:52:44 "ErrorEntity": {
17:52:44 "ExtendedCode": "51016",
17:52:44 "MessageTemplate": "HTTP request body must not be empty.",
17:52:44 "Parameters": [],
17:52:44 "Code": "BadRequest",
17:52:44 "Message": "HTTP request body must not be empty."
17:52:44 }
17:52:44 }
17:52:44 ],
17:52:44 "Innererror": null
17:52:44 }'
17:52:44 At E:\Path\To\Project\build.ps1:2406 char:21
17:52:44 + ... ArmResult = New-AzureRmResourceGroupDeployment -ResourceGroupName $sc ...
17:52:44 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17:52:44 + CategoryInfo : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
17:52:44 + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDep
17:52:44 loymentCmdlet

New-AzureRmResourceGroupDeployment Command not recognizing the JSON paramaters file

I have a JSON parameters file that looks like this.
"parameters": {
"field_1": {
"value": "abc"
},
"field_2": {
"value": 123
},
and I am using the below command to create resources in Azure
New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateFile $templateFilePath -TemplateParameterFile $parametersFilePath
when I run it, for some reason it's not recognizing the parameters that are in the parameters file. It asks me to enter the parameters individually in powershell and then after I enter all of them I get the below error:
New-AzureRmResourceGroupDeployment : 4:07:58 PM - Error: Code=InvalidDeploymentParameterValue; Message=The value of deployment parameter 'parameters' is null. Please specify the value or use the parameter reference. See
https://aka.ms/arm-deploy/#parameter-file for details.
At line:52 char:4
+ New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGro ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet
I am not sure what I am doing wrong. Any help would be greatly appreciated.
Well, it should not recognize it, if you look at the Azure Quickstart templates repository, most of those have parameter files, all of them have a proper structure, while yours don't, here's how a proper parameter file looks like:
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"adminUsername": {
"value": "ghuser"
},
"adminPassword": {
"value": "GEN-PASSWORD"
},
"dnsLabelPrefix": {
"value": "GEN-UNIQUE"
}
}
}
Reference: https://github.com/Azure/azure-quickstart-templates