Skip to content

Instantly share code, notes, and snippets.

@ploegert
Created July 14, 2015 17:14
Show Gist options
  • Select an option

  • Save ploegert/9cb87a99e9f4f99ae59e to your computer and use it in GitHub Desktop.

Select an option

Save ploegert/9cb87a99e9f4f99ae59e to your computer and use it in GitHub Desktop.
Passing Credentials to the Azure DSC Extension Handler Let's say we want to ensure that a virtual machine has a local user with certain credentials. We’ll create a new configuration, located in the file user_configuration.ps1: http://blogs.msdn.com/b/powershell/archive/2014/09/10/secure-credentials-in-the-azure-powershell-desired-state-configura…
<#
Let's say we want to ensure that a virtual machine has a local user with certain credentials.
We’ll create a new configuration, located in the file user_configuration.ps1:
#>
configuration Main
{
param(
[Parameter(Mandatory=$true)]
[ValidateNotNullorEmpty()]
[PSCredential]
$Credential
)
Node localhost {
User LocalUserAccount
{
Username = $Credential.UserName
Password = $Credential
Disabled = $false
Ensure = "Present"
FullName = "Local User Account"
Description = "Local User Account"
PasswordNeverExpires = $true
}
}
}
#Then, using our handy Azure SDK Powershell cmdlets, we publish our configuration to our Azure storage account:
Publish-AzureVMDscConfiguration-ConfigurationPath.\user_configuration.ps1
<#
Next, we will use an existing virtual machine and set our extension handler and
desired configuration to apply to it.
#>
$configurationName = "Main"
$configurationArguments = @{ Credential = Get-Credential }
$configurationArchive = "user_configuration.ps1.zip"
$vm = Get-AzureVM "example-1"
$vm = Set-AzureVMDSCExtension `
-VM $vm `
-ConfigurationArchive $configurationArchive `
-ConfigurationName $configurationName `
-ConfigurationArgument $configurationArguments `
$vm | Update-AzureVM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment