Invoke-DscResource on WindowsFeatureSet fails - dsc

Invoking Invoke-DSCResource on WindowsFeatureSet fails with strange error.
Invoke-DscResource -Name WindowsFeatureSet -Property #{Name = 'FileAndStorage'; Ensure = 'Present' } -Method test -ModuleName PSDesiredStateConfiguration
Invoke-DscResource : Failed to serialize properties into CimInstance.
At line:5 char:1
+ Invoke-DscResource -Name WindowsFeatureSet -Property #{Name = 'FileAn ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-DscResource], SerializationException
+ FullyQualifiedErrorId : System.Runtime.Serialization.SerializationException,Microsoft.PowerShell.DesiredStateConfiguration.Commands.InvokeDscResourceMethodCommand

Composite configurations are never loaded by the LCM. They are only used during compilation and the generated mof has the composite configuration resolved to its underlying resources. So this isn't expected to work. You can try using 'WindowsFeature' instead. This blog explains composite resources in DSC http://nanalakshmanan.com/blog/Composite-Resources-Explained/

This is a known issue. There is an issue filed in PowerShell User Voice, which is marked as 'Survey'. 'Survey' indicates 'We saw this and we are considering it...' per the PowerShell User Voice Home Page.
This is also documented in Chef Discourse here.
And there is an issue open to update the Chef Documentation [here] (https://github.com/chef/chef-web-docs/issues/59) and DSC Documentation here.

Related

Azure Tag for Azure Depolyment not working

I am trying to create a Azure deployment with Tag parameter to put tag on the deployment using command New-AzResourceGroupDeployment like -
New-AzResourceGroupDeployment -ResourceGroupName "demo" -TemplateFile "D:\Templates\storage.json" -Tag #{"CreatedFrom"="PS"; "Env"="Dev";}
but facing this issue -
New-AzResourceGroupDeployment : A parameter cannot be found that matches parameter name 'Tag'.
At line:1 char:102
+ ... Name "demo" -TemplateFile "D:\Templates\storage.json" -Tag #{"Crea ...
+ ~~~~
+ CategoryInfo : InvalidArgument: (:) [New-AzResourceGroupDeployment], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.N
ewAzureResourceGroupDeploymentCmdlet
According to the documentation we can put tag parameter with New-AzResourceGroupDeployment command but its not working for me.
Any help on what I am doing wrong here would be much appreciated!
The command works fine here. Make sure you have the latest version of the commands.
https://learn.microsoft.com/en-us/powershell/azure/new-azureps-module-az?view=azps-6.1.0

What does Object reference not set to an instance of an object error mean when using Add-AzServiceFabricClusterCertificate?

I'm trying to add a new secondary cert to the service fabric, however I receive the following error. does any one have any pointers?
PS C:\WINDOWS\system32> Add-AzServiceFabricClusterCertificate -ResourceGroupName '******' -Name '********' -SecretIdentifier '*************'
Add-AzServiceFabricClusterCertificate : Object reference not set to an instance of an object.
At line:1 char:1
+ Add-AzServiceFabricClusterCertificate -ResourceGroupName '****
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Add-AzServiceFabricClusterCertificate], NullReferenceException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ServiceFabric.Commands.AddAzureRmServiceFabricClusterCertificate
I could not reproduce your issue, it works on my side.
Try to update the Az.ServiceFabric with the command below, my version is 2.0.1.
Update-Module -Name Az.ServiceFabric -Force
In azure keyvault, I use a self-signed certificate, make sure you use the SecretIdentifier below.
Then use the powershell and check the result in the portal.
Add-AzServiceFabricClusterCertificate -ResourceGroupName '<group-name>' -Name 'joyfabric' -SecretIdentifier 'https://joykeyvault.vault.azure.net/secrets/cer135/23c6706daeab47e59caca2431ad96a1c'

Connect-AzureRmAccount - Cannot connect to Azure

While trying to connect Azure from Powershell getting below error:
PS H:\> Connect-AzureRmAccount
Connect-AzureRmAccount : An error occurred while sending the request.
At line:1 char:1
+ Connect-AzureRmAccount
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Connect-AzureRmAccount], HttpRequestException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand
Couple of things to try :
Sometime , powershell cmdlet doesn't give proper error message as it suppressed it , to get the actual error you can try executing with -debug attribute or you can try using DebugPreference like below.
$DebugPreference = "Continue"
Write-Debug -Message "Hello, World"
Alternatively ,Connect-AzureRMAccount cmdlet used TLS 1.0 by default for connecting to azure and sometime it gets blocked by the organization security policy,
Can you setting up something like below:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Additional reference:
Connect-AzureRmAccount : accessing_ws_metadata_exchange_failed
Hope it helps.

Set-AzureRmResource throwing api-version error

I am trying to programmatically add tags to resources in Azure Government. When I try to set the tags on a resource that has no tags I am using the Set-AzureRmResource command. I have tried both setting the ApiVersion and without (without is supposed to use the latest) When I use the Debug flag it shows the version being set but I still get an error below.
Set-AzureRmResource : Cannot validate argument on parameter 'ResourceId'. The argument is null or empty. Provide an
argument that is not null or empty, and then try the command again.
At line:1 char:108
+ ... ONMENT=""; ORGANIZATION="" } -ResourceId $resource.ResourceId -Force ...
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Set-AzureRmResource], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implem
entation.SetAzureResourceCmdlet
The snippet I am trying to run is below.
Set-AzureRmResource -Tag #{ ENVIRONMENT=""; ORGANIZATION="" } -ResourceId $resource.ResourceId -Force
Edit: Specify Azure Government
Edit 2: Removed explicit version setting from code
I tried using the new Az commands in Azure Government:
Set-AzResource -Tag #{ ENVIRONMENT=""; ORGANIZATION="" } -ResourceId $resource.ResourceId -Force
..and it worked fine for me. (I got a serialization error using the older AzureRm commands). FYI... not sure when you tried it yesterday, but there was a DNS issue that caused some service outages, which may have resulted in erroneous errors.
I tested your snippet above against an Azure Government resource and its working correctly using AzureRM module version 6.13.1.
You can your version by running this snippet
Get-Module AzureRM -List
For anyone who sees this in the future. The problem is a known bug in the way Azure encodes the '#' symbol in a ResourceId. So do not use '#' in a resource string.
The code change we are making is to use the following:
$resource.ResourceId = $resource.ResourceId.Replace("#", "%23")
Simple fix if you have the # symbol, or change your governance to not name things with '#'.
Thanks for all the other replies. We had to open a ticket to get this information.

Deploying a forked repro of an azure quick start template

newbie at Github.
I have forked the repro of Azure Quickstart Templates and changed the "install_lamp_moodle.sh" for the "moodle-singlevm-ubuntu" to fit my needs but I cant seem to be able to test this as every-time the newuserscript part of the azuredeploy.json template (which I have locally stored), fails
I have changed the path to the installscript URI from:
"installScriptUri": "[concat('https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/moodle-singlevm-ubuntu/', variables('installScriptName'))]",`
to
"installScriptUri": "[concat('https://github.com/albertramsbottom/azure-quickstart-templates/blob/master/moodle-singlevm-ubuntu/', variables('installScriptName'))]",
And I am using Azure power-shell to create the resource Group and run the template
fails every time on a 404 error for the newuserscript
Obviously doing something very silly here. As I do not know Github I dont want to make changes to anything and thought that by forking the repro I could attempt this. And I have no idea where is newuserscript lives, I assume its an extension for Linux.
New-AzureRmResourceGroupDeployment : 08:56:02 - Resource Microsoft.Compute/virtualMachines/extensions
'myVM/newuserscript' failed with message 'The resource operation completed with terminal
provisioning state 'Failed'.'At line:1 char:1
+ New-AzureRmResourceGroupDeployment -ResourceGroupName mygroup -TemplateFile C:\T ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Resources.NewAzureResourceGroupDeploymentCommand
New-AzureRmResourceGroupDeployment : 08:56:02 - VM has reported a failure when processing extension 'newuserscript'.
Error message: "Script returned an error.
---stdout---
---errout---
install_lamp_moodle.sh: 6: install_lamp_moodle.sh: Syntax error: newline unexpected
".At line:1 char:1
+ New-AzureRmResourceGroupDeployment -ResourceGroupName mygroup -TemplateFile C:\T ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Resources.NewAzureResourceGroupDeploymentCommand
I know this sounds like an Azure quickstart issue but I think it is really a lack of understanding of GitHub and how to use a forked repro
And I aslo assume this has noting to do with the moodle-singlevm-ubuntu template and has more to do with my idiocy :)
Sorry #
You want to link to the "raw" file URI like in the original template. So something like:
"installScriptUri": "[concat('https://raw.githubusercontent.com/albertramsbottom/azure-quickstart-templates/master/moodle-singlevm-ubuntu/', variables('installScriptName'))]"
Note that that location has to be publicly accessible. For a model on how to stage artifacts in a private location you can take a look at this repo:
https://github.com/bmoore-msft/AzureRM-Samples

Resources