WindowsImageTools
WindowsImageTools copied to clipboard
New-Unattend DomainAccount Support?
It appears that domain accounts can be added to local groups.
Expected Behavior
New-Unattended has a parameter Domain accounts to add one or more domain accounts to the local administrators group.
Current Behavior
Not an option.
Possible Solution
Add parameter:
# domain account to add to Administators group in domain\name format
[ValidatePattern('^([a-z0-9]+(-[a-z0-9]+)*)\\[A-Za-z0-9][A-Za-z\d_!@#$%^()\-''{}\.~]{0,14}$')]
[string[]]
$DomainAccount,
After the block of code for $UserAccount:
if ($DomainAccount) {
Write-Verbose -Message "[$($MyInvocation.MyCommand)] Adding Domain Account(s) for $($component.'processorArchitecture') Architecture"
$UserAccountsElement = $component.UserAccounts
$DomainAccountsElement = $UserAccountsElement.AppendChild($unattendXml.CreateElement('DomainAccounts', 'urn:schemas-microsoft-com:unattend'))
$DomainAccountGroups = $DomainAccount | %{$temp = $_.Split('\'); [ordered]@{'domain'=$temp[0]; 'name'=$temp[1]}} | %{[pscustomobject]$_} | sort domain, name | group-object domain
foreach ($DomainAccountGroup in $DomainAccountGroups) {
$DomainAccountListElement = $DomainAccountsElement.AppendChild($unattendXml.CreateElement('DomainAccountList', 'urn:schemas-microsoft-com:unattend'))
$null = $DomainAccountListElement.SetAttribute('action', 'http://schemas.microsoft.com/WMIConfig/2002/State', 'add')
foreach ($Account in $DomainAccountGroup.Group.Name) {
$DomainAccountElement = $DomainAccountListElement.AppendChild($unattendXml.CreateElement('DomainAccount', 'urn:schemas-microsoft-com:unattend'))
$null = $DomainAccountElement.SetAttribute('action', 'http://schemas.microsoft.com/WMIConfig/2002/State', 'add')
$DomainAccountGroupElement = $DomainAccountElement.AppendChild($unattendXml.CreateElement('Group', 'urn:schemas-microsoft-com:unattend'))
$null = $DomainAccountGroupElement.AppendChild($unattendXml.CreateTextNode('Administrators'))
$DomainAccountNameElement = $DomainAccountElement.AppendChild($unattendXml.CreateElement('Name', 'urn:schemas-microsoft-com:unattend'))
$null = $DomainAccountNameElement.AppendChild($unattendXml.CreateTextNode($Account))
}
$DomainElement = $DomainAccountListElement.AppendChild($unattendXml.CreateElement('Domain', 'urn:schemas-microsoft-com:unattend'))
$null = $DomainElement.AppendChild($unattendXml.CreateTextNode($DomainAccountGroup.Name))
}
}
Steps to Reproduce (for bugs)
Context
I've tried to add it, but it does not work. It might be that I do not have access to do so and that GPO will have to be used in my case.
Your Environment
- Module version used:
- Operating System and PowerShell version:
do you have an example of a working unattend.xml?
I made an attempt, but no results yet. I will post back when and if I get something working.
I got your latest code and all the changes seem to work. I added the code for this and tested. The domain account was added to the local Administrators group. Note: I did alter the code to use only amd64 to insure each was processed only once.