Hi Guys,
I am trying to add machines into AD group while OSD deployment and for some reason it doesn't add them to the group.
i am running this step with an account that has access, it doesn't throw any errors but as i mentioned it doesn't add them into the group.
Please let me know what i am doing wrong.
here is the script...
$DomainName = (Get-WmiObject Win32_ComputerSystem).Domain
$ComputerName = (Get-WmiObject Win32_ComputerSystem).Name
$GroupName = "CN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
$GroupPath = "LDAP://" + $GroupName
Write-Host "DomainName: $DomainName"
Write-Host "Computername: $Computername"
Write-Host "Groupname: $Groupname"
Write-Host "Grouppath: $Grouppath"
$isMember = new-object DirectoryServices.DirectorySearcher([ADSI]"")
$ismember.filter = "(&(objectClass=computer)(SamAccountName=$Computername$)(memberof=$GroupName))"
$isMemberResult = $isMember.FindOne()
Write-Host "Membership query result:"$isMemberResult.Path
If ($isMemberResult) {
Write-Host "Computer is already member of the Windows 10 group. Exiting..."
Stop-Transcript
Exit 0
}
Else
#If the computer is NOT a member of the group, add it.
{
Write-Host "Computer is not a member of the target Windows 10 group. Adding..."
$searcher = New-Object DirectoryServices.DirectorySearcher([ADSI]"")
$searcher.filter = "(&(objectClass=computer)(SamAccountName=$Computername$))"
$FoundComputer = $searcher.FindOne()
$P = $FoundComputer | select path
$ComputerPath = $p.path
$Group = [ADSI]"$GroupPath"
$Group.Add("$ComputerPath")
$Group.SetInfo()
Stop-Transcript
}
and my TS step..

I am trying to add machines into AD group while OSD deployment and for some reason it doesn't add them to the group.
i am running this step with an account that has access, it doesn't throw any errors but as i mentioned it doesn't add them into the group.
Please let me know what i am doing wrong.
here is the script...
$DomainName = (Get-WmiObject Win32_ComputerSystem).Domain
$ComputerName = (Get-WmiObject Win32_ComputerSystem).Name
$GroupName = "CN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
$GroupPath = "LDAP://" + $GroupName
Write-Host "DomainName: $DomainName"
Write-Host "Computername: $Computername"
Write-Host "Groupname: $Groupname"
Write-Host "Grouppath: $Grouppath"
$isMember = new-object DirectoryServices.DirectorySearcher([ADSI]"")
$ismember.filter = "(&(objectClass=computer)(SamAccountName=$Computername$)(memberof=$GroupName))"
$isMemberResult = $isMember.FindOne()
Write-Host "Membership query result:"$isMemberResult.Path
If ($isMemberResult) {
Write-Host "Computer is already member of the Windows 10 group. Exiting..."
Stop-Transcript
Exit 0
}
Else
#If the computer is NOT a member of the group, add it.
{
Write-Host "Computer is not a member of the target Windows 10 group. Adding..."
$searcher = New-Object DirectoryServices.DirectorySearcher([ADSI]"")
$searcher.filter = "(&(objectClass=computer)(SamAccountName=$Computername$))"
$FoundComputer = $searcher.FindOne()
$P = $FoundComputer | select path
$ComputerPath = $p.path
$Group = [ADSI]"$GroupPath"
$Group.Add("$ComputerPath")
$Group.SetInfo()
Stop-Transcript
}
and my TS step..
