/build/static/layout/Breadcrumb_cap_w.png

Join AD group script

Hello all,
I just started using the K appliances and so far so good. Right now I'm at a loss. I have no issues pulling/deploying images, but now comes the fun part. I was able to join the domain, using one of the pre-installed post scripts available to me. But in our environment, we must be able to not only join the domain, but move the computer to the correct OU and make sure the computer is receiving the correct name in order not to cause any conflicts. Any help would be appreciated.

Thank you

0 Comments   [ + ] Show comments

Answers (6)

Posted by: dyehardfan 13 years ago
Second Degree Blue Belt
0
This is the script that came pre-installed on my K2, it looks like it should have the functionality you need.


#!/bin/bash

### You must edit these for your specific environment

# 1) fully qualified DNS name of Active Directory Domain.
domain="test.example.com"

# 2) username of a privileged network user.
udn=""

# 3) password of a privileged network user.
password=""

# 4) Distinguished name of container for the computer
ou="ou=Computers,ou=lab,DC=test,DC=example,DC=com"

# 5) 'enable' or 'disable' automatic multi-domain authentication
alldomains="enable"

### End of configuration

# Get the local computer's name.
computerid=`/usr/sbin/scutil --get LocalHostName`

# Activate the AD plugin, just to be sure
defaults write /Library/Preferences/DirectoryService/DirectoryService "Active Directory" "Active"
plutil -convert xml1 /Library/Preferences/DirectoryService/DirectoryService.plist

# Bind to AD
dsconfigad -f -a $computerid -domain $domain -u "$udn" -p "$password" -ou "$ou"
dsconfigad -alldomains $alldomains

# Add the AD node to the search path
if [ "$alldomains" = "enable" ]; then
csp="/Active Directory/All Domains"
else
csp="/Active Directory/$domain"
fi

dscl /Search -append / CSPSearchPath "$csp"
dscl /Search -create / SearchPolicy dsAttrTypeStandard:CSPSearchPath
dscl /Search/Contacts -append / CSPSearchPath "$csp"
dscl /Search/Contacts -create / SearchPolicy dsAttrTypeStandard:CSPSearchPath

# Restart Directory Service
killall DirectoryService
sleep 2

exit 0
Posted by: dchristian 13 years ago
Red Belt
0
jguitierrez,

This is what i have been using to move computers to specific OUs.

I have a little VBS that checks a text file.

The text file has the computer name prefixes then a "|" and finally the OU the computer should be moved to.
Option Explicit
Dim criteria
Dim newOU
Dim compName

Const SearchBaseDN="DC=mydomain,DC=com"
Const defualtComputerOU = "CN=Computers"


compName = GetComputerName()
criteria=GetComputerNamePrefix()
newOU=FindValue(UCase(criteria))

If (newOU <> "") Then
MoveComputer SearchBaseDN,defualtComputerOU,newOU,compName
Else
WScript.Echo "no path found"
End if


Function GetComputerName()
Dim objNTInfo
Set objNTInfo = CreateObject("WinNTSystemInfo")

GetComputerName= objNTInfo.ComputerName
End Function

Function GetComputerNamePrefix()
Dim objNTInfo
Dim xname
Const delimeter = "-"
Set objNTInfo = CreateObject("WinNTSystemInfo")

xname = objNTInfo.ComputerName
If(InStr(xname,delimeter)> 0) Then
GetComputerNamePrefix=Left(xname,InStr(xname,delimeter)-1)
Else
GetComputerNamePrefix = xname
End If
End function


Function FindValue(xFindValue)
Dim objFSO
Dim objTextFile
Dim strNextLine
Dim arrServiceList
Dim i
Dim oDic
Set oDic = CreateObject("scripting.dictionary")

Const InputFile = "inputer.txt"
Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
(InputFile, ForReading)

Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
arrServiceList = Split(strNextLine , "|")
oDic.Add arrServiceList(0),arrServiceList(1)
Loop

FindValue = oDic.Item(xFindValue)
End Function

Sub MoveComputer(xSearchBase,xdefualtComputerOU,xnewOU,xCompName)
Dim baseOU
Dim newDest
Dim objNewOU
Dim objMoveComputer

baseOU = "LDAP://CN=" & xCompName & "," & xdefualtComputerOU & "," & xSearchBase
newDest = "LDAP://" & xnewOU
WScript.Echo baseOU
WScript.Echo newDest
Set objNewOU = GetObject(newDest)

Set objMoveComputer = objNewOU.MoveHere _
(baseOU, "CN=" & xcompName)

End Sub


Example text file. Must be named "inputer.txt"
THE|OU=Computers,OU=Test Enviroment,DC=mydomain,DC=com
VANT|OU=Computers,OU=IT Department,DC=mydomain,DC=com


I think all you'll need to do is adjust this line to point to your domain.
Const SearchBaseDN="DC=mydomain,DC=com"

Hope this helps
Posted by: jgutierrez 13 years ago
Senior Yellow Belt
0
ORIGINAL: dyehardfan

This is the script that came pre-installed on my K2, it looks like it should have the functionality you need.


#!/bin/bash

### You must edit these for your specific environment

# 1) fully qualified DNS name of Active Directory Domain.
domain="test.example.com"

# 2) username of a privileged network user.
udn=""

# 3) password of a privileged network user.
password=""

# 4) Distinguished name of container for the computer
ou="ou=Computers,ou=lab,DC=test,DC=example,DC=com"

# 5) 'enable' or 'disable' automatic multi-domain authentication
alldomains="enable"

### End of configuration

# Get the local computer's name.
computerid=`/usr/sbin/scutil --get LocalHostName`

# Activate the AD plugin, just to be sure
defaults write /Library/Preferences/DirectoryService/DirectoryService "Active Directory" "Active"
plutil -convert xml1 /Library/Preferences/DirectoryService/DirectoryService.plist

# Bind to AD
dsconfigad -f -a $computerid -domain $domain -u "$udn" -p "$password" -ou "$ou"
dsconfigad -alldomains $alldomains

# Add the AD node to the search path
if [ "$alldomains" = "enable" ]; then
csp="/Active Directory/All Domains"
else
csp="/Active Directory/$domain"
fi

dscl /Search -append / CSPSearchPath "$csp"
dscl /Search -create / SearchPolicy dsAttrTypeStandard:CSPSearchPath
dscl /Search/Contacts -append / CSPSearchPath "$csp"
dscl /Search/Contacts -create / SearchPolicy dsAttrTypeStandard:CSPSearchPath

# Restart Directory Service
killall DirectoryService
sleep 2

exit 0



I should have mentioned this earlier. I tried this one and no dice. But thanks
Posted by: jgutierrez 13 years ago
Senior Yellow Belt
0
I'll give this a shot.
Thanks

ORIGINAL: dchristian

jguitierrez,

This is what i have been using to move computers to specific OUs.

I have a little VBS that checks a text file.

The text file has the computer name prefixes then a "|" and finally the OU the computer should be moved to.
Option Explicit
Dim criteria
Dim newOU
Dim compName

Const SearchBaseDN="DC=mydomain,DC=com"
Const defualtComputerOU = "CN=Computers"


compName = GetComputerName()
criteria=GetComputerNamePrefix()
newOU=FindValue(UCase(criteria))

If (newOU <> "") Then
MoveComputer SearchBaseDN,defualtComputerOU,newOU,compName
Else
WScript.Echo "no path found"
End if


Function GetComputerName()
Dim objNTInfo
Set objNTInfo = CreateObject("WinNTSystemInfo")

GetComputerName= objNTInfo.ComputerName
End Function

Function GetComputerNamePrefix()
Dim objNTInfo
Dim xname
Const delimeter = "-"
Set objNTInfo = CreateObject("WinNTSystemInfo")

xname = objNTInfo.ComputerName
If(InStr(xname,delimeter)> 0) Then
GetComputerNamePrefix=Left(xname,InStr(xname,delimeter)-1)
Else
GetComputerNamePrefix = xname
End If
End function


Function FindValue(xFindValue)
Dim objFSO
Dim objTextFile
Dim strNextLine
Dim arrServiceList
Dim i
Dim oDic
Set oDic = CreateObject("scripting.dictionary")

Const InputFile = "inputer.txt"
Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
(InputFile, ForReading)

Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
arrServiceList = Split(strNextLine , "|")
oDic.Add arrServiceList(0),arrServiceList(1)
Loop

FindValue = oDic.Item(xFindValue)
End Function

Sub MoveComputer(xSearchBase,xdefualtComputerOU,xnewOU,xCompName)
Dim baseOU
Dim newDest
Dim objNewOU
Dim objMoveComputer

baseOU = "LDAP://CN=" & xCompName & "," & xdefualtComputerOU & "," & xSearchBase
newDest = "LDAP://" & xnewOU
WScript.Echo baseOU
WScript.Echo newDest
Set objNewOU = GetObject(newDest)

Set objMoveComputer = objNewOU.MoveHere _
(baseOU, "CN=" & xcompName)

End Sub


Example text file. Must be named "inputer.txt"
THE|OU=Computers,OU=Test Enviroment,DC=mydomain,DC=com
VANT|OU=Computers,OU=IT Department,DC=mydomain,DC=com


I think all you'll need to do is adjust this line to point to your domain.
Const SearchBaseDN="DC=mydomain,DC=com"

Hope this helps
Posted by: jgutierrez 13 years ago
Senior Yellow Belt
0
When I create a Shell script though, it only lets me click on Mac OS X. i'm running Windows. Will this be a problem?
Posted by: dchristian 13 years ago
Red Belt
0
shell scripts are only for mac.

If you are trying to do the example i provided you need to configure it as an application.

Since it will be a multiple file application you need to zip up the vbs and the input text file.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ