During the provisioning of a WindowsServer 2016 Datacenter
image in Packer
using Azure-ARM
, I need the randomly generated password used on the build VM, so that I can set the computer's domain using the code:
$password = ConvertTo-SecureString $args[1] -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ($args[0], $password)
Add-Computer -DomainName $domain -Credential $credential
However, I do not have access to the password generated by the Packer Build VM, and the documentation only states that the password is randomly generated, but not how to retrieve it.
Is there any way to get the credentials from Packer, or will I need to resort to some Powershell wizardry in an Administrator shell to get the password in plain text?
As per Matt Schuchard, especially for software provisioning, use the random generated admin password and override it then or later after the artifact deployed with an infra provisioner if needed to be deterministic.
Is there any way to get the credentials from Packer , or will I need to resort to some Powershell wizardry in an Administrator shell to get the password in plain text?
Try this below code which outputs password in plain text!
Azure PowerShell:
$sp = New-AzADServicePrincipal -DisplayName "PackerSP$(Get-Random)"
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($sp.Secret)
$plainPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
Then output the password and application ID.
$plainPassword
$sp.ApplicationId
For more details refer this documentation-of-build-images-with-packer-arm