Crazy Boy
Crazy Boy

Reputation: 1

Powershell Add-DhcpServerInDC Access Denied When Using it with Invoke-Command

I'm trying to automate the process of setting up a multi-network DHCP. 172.16.0.13 is the network the Adatum domain is on. 172.16.18.21 is the network the relay agent is on. Both of these have the same DNS name of "AutoDHCP" (Same Machine). 172.16.0.10 is the Domain Controller (LON-DC1) that I am trying to authorize the DHCP server on.

I ran the following script:

$DCUser = "Adatum\Administrator"
$DCPass = ConvertTo-SecureString "Pa55w.rd" -AsPlainText -Force
$DCRemoteCredential = New-Object System.Management.Automation.PSCredential ($DCUser, $DCPass)
Set-Item WSMan:\localhost\Client\TrustedHosts "172.16.0.10"
$DC1 = New-PSSession -ComputerName 172.16.0.10 -Credential $DCRemoteCredential
Invoke-Command -Session $DC1 -Scriptblock {Add-DhcpServerInDC -DnsName "AutoDHCP" -IPAddress 172.16.18.21}
Invoke-Command -Session $DC1 -Scriptblock {Add-DhcpServerInDC -DnsName "AutoDHCP" -IPAddress 172.16.0.13}
Remove-PSSession $DC1

What I wanted to get:

WARNING: The DHCP server autodhcp with IP address 172.16.18.21 is already authorized in Active Directory. The authorization check on the DHCP server has been initiated.

WARNING: The DHCP server autodhcp with IP address 172.16.0.13 is already authorized in Active Directory. The authorization check on the DHCP server has been initiated.

What I actually got:

WARNING: The DHCP server autodhcp with IP address 172.16.18.21 is already authorized in Active Directory
Failed to initiate the authorization check on the DHCP server. Error: Access is denied. (5).

WARNING: The DHCP server autodhcp with IP address 172.16.0.13 is already authorized in Active Directory.
Failed to initiate the authorization check on the DHCP server. Error: Access is denied. (5).


When I run it on the (LON-DC1) Directly, it does just fine, but that's not what I want. I need it to run from a larger script file running on AutoDHCP so it happens handsfree*. It fails to initiate the authorization check with everything I've tried so far. I'm not sure what to do next, I'm not worried about security as these are Virtual Machines and get recycled into other Projects or other Labs.

Domain: Adatum.com
Accounts Used: Adatum\Administrator
*willing to enter password after server restart.

Upvotes: 0

Views: 220

Answers (0)

Related Questions