Can't Add Azure DSC Extension to VM in ARM mode - powershell

I need to create VM based on image (SQL Server 2016 on Windows Server 2016) and add DSC extension to it by powershell. I have template.json and it's parameters.json files that I saved when was creating VM(sql2016 server on windows 2016 server) in portal(in parameters file I define url where published sdc zip and admin password).
Zip file withconfiguration is located on github public repository. And it was created by powershell publish commandlet.
After this my next steps are:
Login-AzureRmAccount
# Create resource group
New-AzureRmResourceGroup -Name orsql1 -Location 'North Europe' # succeed
# Define deployment variables
$Deployment = #{
ResourceGroupName = 'orsqllast';
Mode = 'Complete';
TemplateFile = 'template.json';
TemplateParameterFile = 'parameters.json';
Force = $true;
}
New-AzureRmResourceGroupDeployment #Deployment -DeploymentDebugLogLevel All
dsc1.ps1 contents:
configuration IISInstall
{
node ("localhost")
{
WindowsFeature IIS
{
Ensure = "Present"
Name = "Web-Server"
}
}
}
After a lot of time I get this errors:
New-AzureRmResourceGroupDeployment : 14:02:10 - Resource Microsoft.Resources/deployments 'Microsoft.DSC-20161
010122604' failed with message '{
"status": "Failed",
"error": {
"code": "ResourceDeploymentFailure",
"message": "The resource operation completed with terminal provisioning state 'Failed'.",
"details": [
{
"code": "DeploymentFailed",
"message": "At least one resource deployment operation failed. Please list deployment operations for
details. Please see https://aka.ms/arm-debug for usage details.",
"details": [
{
"code": "Conflict",
"message": "{\r\n \"status\": \"Failed\",\r\n \"error\": {\r\n \"code\": \"ResourceDeploymen
tFailure\",\r\n \"message\": \"The resource operation completed with terminal provisioning state 'Failed'.
\",\r\n \"details\": [\r\n {\r\n \"code\": \"VMExtensionProvisioningError\",\r\n \"mess
age\": \"VM has reported a failure when processing extension 'Microsoft.Powershell.DSC'. Error message: \\\"E
rror unpacking 'dsc1.ps1.zip'; verify this is a valid ZIP package.\\nError details: Exception calling \\\"Ext
ractToDirectory\\\" with \\\"2\\\" argument(s): \\\"End of Central Directory record could not be found.\\\"\\
\".\"\r\n }\r\n ]\r\n }\r\n}"
}
]
}
]
}
}'
At line:14 char:1
+ New-AzureRmResourceGroupDeployment #Deployment -DeploymentDebugLogLe ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResour
ceGroupDeploymentCmdlet
New-AzureRmResourceGroupDeployment : 14:02:10 - At least one resource deployment operation failed. Please lis
t deployment operations for details. Please see https://aka.ms/arm-debug for usage details.
At line:14 char:1
+ New-AzureRmResourceGroupDeployment #Deployment -DeploymentDebugLogLe ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResour
ceGroupDeploymentCmdlet
New-AzureRmResourceGroupDeployment : 14:02:10 - Template output evaluation skipped: at least one resource dep
loyment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-debug
for usage details.
At line:14 char:1
+ New-AzureRmResourceGroupDeployment #Deployment -DeploymentDebugLogLe ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResour
ceGroupDeploymentCmdlet
New-AzureRmResourceGroupDeployment : 14:02:10 - Template output evaluation skipped: at least one resource dep
loyment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-debug
for usage details.
At line:14 char:1
+ New-AzureRmResourceGroupDeployment #Deployment -DeploymentDebugLogLe ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResour
ceGroupDeploymentCmdlet
The zip is valid and I use anouther one - the same error.
Part of parameters.json
"ex0_vmName": {
"value": "node1"
},
"ex0_location": {
"value": "northeurope"
},
"ex0_modulesUrl": {
"value": "https://github.com/myname/mydsc/blob/master/dsc1.ps1.zip"
},
"ex0_configurationFunction": {
"value": "dsc1.ps1\\IISInstall"
},
"ex0_wmfVersion": {
"value": "latest"
},
"ex0_privacy": {
"value": "Enable"
},
"ex0_version": {
"value": "2.8"
}

I would suggest you consult logs in the VM itself in c:\windowsazure\logs. Under c:\extensions (now C:\Packages\Plugins) you can find your zip package and DSC extension files.
The easiest way to troubleshoot that would be to create the DSC extension using the portal. If it fails with the same error you would want to recreate the zip file. I've had the same errors with the zip package and solved them by recreating it.
I would also suggest you move to Azure Automation. Depending on your scope, you might be okay with 500 free minutes monthly and you can upload mof's to Azure Automation. And I've found Azure Automation to be much more consistent than DSC extension.

Related

How to call long-running User Data Script with parameter from CloudFormation?

I have a PowerShell script, that when runs, installs a large application and start a server. This process takes about 20 minutes to run.
I would like to start this install process when the server is first created to avoid having to RDP into the server, and start the script manually.
The problem I'm having is that there is no sign of the user data script running in the server. There are no logs in C:\Program Files\Amazon.
The cloudformation script looks like this:
"UserData": { "Fn::Base64": { "Fn::Join": ["", [
"<powershell>\n",
"Set-Location C:\\Users\\Administrator\\Documents\\installer-and-scripts\\ \n",
".\\AddNewAppServer.ps1 ", { "Ref" : "RDSEndpoint" }, " ", { "Ref" : "DBAdminUser" }, " ", { "Ref" : "DBAdminPassword" }, " ", { "Ref" : "S3BackupFileARN" }, " ", { "Ref" : "NewdbName" }, " \n",
"</powershell>"]]
}}
The five variables in UserData are parameters of the Cloudformation script and are just Strings.
Why do I not see any sign of this script running? Also, will having a 20-minute script cause issues in logging into the server or even run at all?
Thanks!

How to debug Azure Data Factory V2 Invalid Trigger Type?

I created a new ADF V2 pipleline with a tumbling window trigger via powershell. When starting the pipeline I get an error:
Start-AzureRmDataFactoryV2Trigger -ResourceGroupName $ResourceGroup -DataFactoryName $DataFactoryName -Name "DailyTriggerCookForecastPipeline"
[ERROR] Start-AzureRmDataFactoryV2Trigger : HTTP Status Code: BadRequest
[ERROR] Error Code: BadRequest
[ERROR] Error Message: Invalid trigger type: Trigger
[ERROR] Request Id: 6591ae6b-902d-4b25-9f62-c6bb67796d57
[ERROR] Timestamp (Utc):01/08/2018 16:05:30
[ERROR] At line:1 char:1
[ERROR] + Start-AzureRmDataFactoryV2Trigger -ResourceGroupName $ResourceGroup - ...
[ERROR] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ERROR] + CategoryInfo : CloseError: (:) [Start-AzureRmDataFactoryV2Trigger], ErrorResponseException
[ERROR] + FullyQualifiedErrorId : Microsoft.Azure.Commands.DataFactoryV2.StartAzureDataFactoryTriggerCommand
[ERROR]
My trigger is defined as:
{
"name": "DailyTriggerCookForecastPipeline",
"properties": {
"type": "TumblingWindowTrigger",
"typeProperties": {
"frequency": "Hour",
"interval": "24",
"startTime": "2018-01-01T04:00:00Z",
"retryPolicy": {
"count": 2,
"intervalInSeconds": 30
},
"maxConcurrency": 1
},
"pipeline": {
"pipelineReference": {
"type": "PipelineReference",
"referenceName": "CookForecastPipeline"
},
"parameters": {
"SliceStart": "#trigger().outputs.windowStartTime"
}
}
}
}
I have no idea how to debug this further. Is there a way to get a more detailed error message? I couldn't find one in the portal.
Thanks!
Like Martin suggested in the comments a good first step is to add -verbose flag. Unfortunately it doesn't add much info.
The second step for debugging is to make sure your setup is correct. In this case it turned out that TumblingWindowTrigger was just released but I had an older SDK. This dependency wasn't documented anywhere. So turns out the errors are pretty accurate.

New-AzureRmResourceGroupDeployment command giving error

When I run the New-AzureRmResourceGroupDeployment and pass a JSON parameter file, I get the below error:
New-AzureRmResourceGroupDeployment : 2:29:31 PM - Resource Microsoft.Sql/servers 'qsservername' failed with message '{
"code": "15021",
"message": "Invalid value given for parameter Login. Specify a valid parameter value.",
"target": null,
"details": [
{
"code": "15021",
"message": "Invalid value given for parameter Login. Specify a valid parameter value.",
"target": null,
"severity": "16"
}
],
"innererror": []
}'
At M:\Azure\Azure Scripts\Something\somethingdeploy.psm1:63 char:4
+ New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGro ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet
However, when I run the same command but pass the parameters instead of the file, it works fine. any ideas what I may be missing?
For me, this error happened when I tried to run ARM templates with the existing SQL Azure instance resource. The problem was that in the template I specified a DB username which didn't match the admin username of the existing instance. It's ok to update the password, but the username has to remain the same for the life of SQL Azure instance,

How many status of azure deployment could be

All, I am trying to deploy my cloud service to Windows Azure. Currently It works fine. But I still try to understand the detail inside of it . Like below Power Shell script.
The script is trying to get the status of a deplpoyment in the Staging slot after New-AzureDeployment has been executed successfully.
while ($True) {
$deployment = Get-AzureDeployment -ServiceName $CloudServiceName -Slot Staging
if ($deployment.Status -ne 'Running') {
continue
}
$notReadyList = $deployment.RoleInstanceList | Where-Object InstanceStatus -ne 'ReadyRole'
if (!$notReadyList) {
break
}
$errorStatusList = #('RestartingRole';'CyclingRole';'FailedStartingRole';'FailedStartingVM';'UnresponsiveRole')
$errorList = $notReadyList | Where-Object InstanceStatus -in $errorStatusList
if ($errorList) {
throw 'Role in staging fail to start for some of these reasons:' + ($errorList | Format-List | Out-String)
}
Start-Sleep -Seconds 10
}
I have some questions about the script . Please try to help me .thanks.
What is the object type of Get-AzureDeployment return ? I search it in the Help Doc. But did't found any information about it.
How many possible status except Running the Get-AzureDeployment could return ?
Is there any possibility never break in the loop ?
Thanks.
What is the object type of Get-AzureDeployment return ? I search it in
the Help Doc. But did't found any information about it.
As mentioned in the documentation, this operation returns an object of type DeploymentInfoContext. You can find more about this object here: https://github.com/WindowsAzure/azure-sdk-tools/blob/master/WindowsAzurePowershell/src/Commands.ServiceManagement/Model/DeploymentInfoContext.cs. However if you look at the source code for Get-AzureDeployment here: https://github.com/WindowsAzure/azure-sdk-tools/blob/master/WindowsAzurePowershell/src/Commands.ServiceManagement/HostedServices/GetAzureDeployment.cs, you'll notice that it returns the following:
return new DeploymentInfoContext(d)
{
OperationId = s.Id,
OperationStatus = s.Status.ToString(),
OperationDescription = CommandRuntime.ToString(),
ServiceName = this.ServiceName
};
How many possible status except Running the Get-AzureDeployment could
return ?
You can find the list of possible statuses here: http://msdn.microsoft.com/en-us/library/windowsazure/ee460804.aspx.
Following is copied from the link above:
Is there any possibility never break in the loop ?
I'm not sure about that. I guess you will need to test it out thoroughly. The statuses may change with the newer versions of Service Management API so you would need to ensure that your code covers all possible statuses.
Get-AzureDeployment returns an object of schema shown below
SdkVersion :
RollbackAllowed : False
Slot : Production
Name :
DeploymentName : [Somename]
Url : http://[Somename].cloudapp.net/
Status : Suspended
CurrentUpgradeDomain : 0
CurrentUpgradeDomainState :
UpgradeType :
RoleInstanceList : {}
Configuration :
DeploymentId : [SomeGUID]
Label : [Somename]
VNetName : [Somename]
DnsSettings :
OSVersion :
RolesConfiguration : {[[Somename], Microsoft.WindowsAzure.Commands.ServiceManagement.Model.RoleConfiguration]}
ServiceName : [Somename]
OperationDescription : Get-AzureDeployment
OperationId : 1801bce8-73b4-5a74-9e80-e03d04ff405b
OperationStatus : Succeeded

unable to export windows cert as pkcs12 - "Key not valid for use in specified state"

I am trying to export a cert with powershell to pkcs12. I can export it fine in MMC. But powershell barfs
PS C:\Users\paul> $cert.export('PFX'," pass")
Exception calling "Export" with "2" argument(s): "Key not valid for use in specified state.
"
At line:1 char:13
+ $cert.export <<<< ('PFX'," pass")
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
The private key is exportable
PS C:\Users\paul> $cert.privatekey.cspkeycontainerinfo
MachineKeyStore : True
ProviderName : Microsoft RSA SChannel Cryptographic Provider
ProviderType : 12
KeyContainerName : fd6ce48f23c5a94dee97bf7e87ef3da2_2868494a-a319-4976-80a7-e0f129e23cfd
UniqueKeyContainerName : fd6ce48f23c5a94dee97bf7e87ef3da2_2868494a-a319-4976-80a7-e0f129e23cfd
KeyNumber : Exchange
Exportable : True
HardwareDevice : False
Removable : False
Accessible : True
Protected : False
CryptoKeySecurity : System.Security.AccessControl.CryptoKeySecurity
RandomlyGenerated : False
running as local admin
This seems like a long shot, but have you tried using the Pfx enumeration instead of the string?
$pfx = [System.Security.Cryptography.X509Certificates.X509ContentType]::Pfx
$cert.Export($pfx,"pass")
The reason I ask, is that if you look at the value underlying the enumeration, Pfx actually has a value of 3.