Sep 04 2023 06:36 PM - edited Sep 04 2023 06:46 PM
Hi
I am trying to use this in my task sequence to verify if the computer object name already exists in AD. This script works absolutely fine from a machine already joined to the domain. I am trying to execute the below script during the WinPE stage, but end up with error in below step in the script.
# Create an object "DirectoryEntry" and specify the domain, username and password
$Domain = New-Object -TypeName System.DirectoryServices.DirectoryEntry
-ArgumentList $DomainDN,$($Credential.UserName),$($Credential.GetNetworkCredential().password)
Error encountered is:
Format-default : The following exception occurred while retrieving member distinguishedName: Unknown error 0x80005000
Complete Script:
#Computer hostname
$varCompName = "W1022H2"
#Define the Credential
$Credential = Get-Credential -Credential Tucson\Administrator
# Create an ADSI Search
$Searcher = New-Object -TypeName System.DirectoryServices.DirectorySearcher
# Searchh fiter to computers only
$searcher.filter = “(&(objectClass=computer)(sAMAccountName= $($varCompName)$))”
# Get the current domain
#$DomainDN = $(([adsisearcher]"").Searchroot.path)
#$DomainDN = $(([adsisearcher]"sAMAccountName=$($varCompName)$").FindOne().path)
$DomainDN = 'LDAP://DC=Tucson,DC=com'
# Create an object "DirectoryEntry" and specify the domain, username and password
$Domain = New-Object `
-TypeName System.DirectoryServices.DirectoryEntry `
-ArgumentList $DomainDN,$($Credential.UserName),$($Credential.GetNetworkCredential().password)
# Add the Domain to the search
$Searcher.SearchRoot = $Domain
# Execute the Search
$Searcher.FindAll()
Kindly advice how can i correct/tweak the script to work during WinPE. Thank you
Dec 21 2023 06:02 AM
Hello @RameshRK, did you manage to get this working? I'm facing a similar issue. Thanks
Feb 19 2024 08:12 PM
SolutionFeb 19 2024 08:12 PM
Solution