Skip to content

New-Unattend DomainAccount Support? #8

@drstonephd

Description

@drstonephd

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions