When I run the following script on a computer it works perfectly but when I run the script as part of a MDT task sequence I get an error.
The code is for automatically adding the computer being imaged to a security group for Direct Access. I have tried running it with and without a domain admin account.
Any help would be appreciated.
Thanks,
Andy
Code:
$ComputerName = gc env:computername
$GroupPath = "LDAP://CN=DirectAccessComputers,OU=Security Groups,DC=xxx,DC=xx,DC=xx,DC=xx"
$computerPath = "LDAP://CN=$ComputerName,OU=NewComputers,DC=xxx,DC=xx,DC=xx,DC=xx"
$Group =[ADSI]"$GroupPath"
$Group.Add("$computerPath")
$Group.SetInfo()
Error Messages:
The following exception occurred while retrieving member "Add": "The specified domain either does not exist or could not be contacted."TaskSequencePSHost03/24/2015 2:09:24 PM0 (0x0000)
At \\AOTWDS01V\DeploymentShare$\Scripts\dagroup.ps1:7 char:1
+ $Group.Add("$computerPath")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~TaskSequencePSHost03/24/2015 2:09:24 PM0 (0x0000)
NotSpecified: (:) [], ExtendedTypeSystemException TaskSequencePSHost03/24/2015 2:09:24 PM0 (0x0000)
The following exception occurred while retrieving member "SetInfo": "The specified domain either does not exist or could not be contacted.
"TaskSequencePSHost03/24/2015 2:09:24 PM0 (0x0000)
At \\AOTWDS01V\DeploymentShare$\Scripts\dagroup.ps1:8 char:1
+ $Group.SetInfo()
+ ~~~~~~~~~~~~~~~~TaskSequencePSHost03/24/2015 2:09:24 PM0 (0x0000)
NotSpecified: (:) [], ExtendedTypeSystemException TaskSequencePSHost03/24/2015 2:09:24 PM0 (0x0000)
TSHOST: Script completed with return code 0 TaskSequencePSHost03/24/2015 2:09:24 PM0 (0x0000)