Examples/Resources/Computer/3-RenameComputerInDomain.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<#
    .EXAMPLE
    This example will change the machines name 'Server01' while remaining
    joined to the current domain.
    Note: this requires a credential for renaming the machine on the
    domain.
#>

Configuration Example
{
    param
    (
        [Parameter()]
        [System.String[]]
        $NodeName = 'localhost',

        [Parameter(Mandatory = $true)]
        [ValidateNotNullorEmpty()]
        [System.Management.Automation.PSCredential]
        $Credential
    )

    Import-DscResource -Module ComputerManagementDsc

    Node $NodeName
    {
        Computer NewName
        {
            Name       = 'Server01'
            Credential = $Credential # Domain credential
        }
    }
}