#177669 - 2007-07-09 09:44 PM
user to computer desc
|
ack2000
Fresh Scripter
Registered: 2007-07-09
Posts: 8
|
Before I write it. Has anyone created a script to take the username and write to that computer account's description in AD.
Thanks
Makes finding users easier.
|
|
Top
|
|
|
|
#177688 - 2007-07-10 03:56 PM
Re: user to computer desc
[Re: NTDOC]
|
ack2000
Fresh Scripter
Registered: 2007-07-09
Posts: 8
|
I am use to writing for ASP not kix. I need a little help this keeps erroring on line 15 expected ')'!
Dim $oRootDSE, $sDomainADsPath, $ldapPath, $filter, $entry, $searcher, $result, $DirectoryServices $oRootDSE = GetObject("LDAP://RootDSE") $sDomainADsPath = "LDAP://" & $oRootDSE.Get("defaultNamingContext") $ldapPath = $sDomainADsPath $filter = String.Format("(&(objectCategory=computer)(name=" & @wksta &"))") $entry = New $DirectoryServices.DirectoryEntry($ldapPath) $searcher = New $DirectoryServices.DirectorySearcher($entry, $filter, New String() {"description", "ADsPath"})
$result as $DirectoryServices.SearchResult = $searcher.FindOne() If Not IsNothing($result) Then If ($result.Properties.Contains("description")) Then $TxtDesc1 = $result.Properties("description")(0) End If If ($result.Properties.Contains("AdsPath")) Then $lblAdsPath = $result.Properties("AdsPath")(0) End If End If
Dim $objParent As New $DirectoryServices.DirectoryEntry($lblAdsPath, "administrator", "password", $DirectoryServices.AuthenticationTypes.Secure) $objParent.Properties("description").Value = (@FULLNAME) $objParent.CommitChanges()
|
|
Top
|
|
|
|
#177690 - 2007-07-10 04:42 PM
Re: user to computer desc
[Re: ack2000]
|
Arend_
MM club member
   
Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
|
And replace the & signs with the + signs 
Also this won't work:
Dim $objParent As New $DirectoryServices.DirectoryEntry($lblAdsPath, "administrator", "password", $DirectoryServices.AuthenticationTypes.Secure)
Kix does not support type declaration as of yet. (Something I hope to be implemented in the future though)
Edited by apronk (2007-07-10 04:44 PM)
|
|
Top
|
|
|
|
#177692 - 2007-07-10 05:36 PM
Re: user to computer desc
[Re: Arend_]
|
ack2000
Fresh Scripter
Registered: 2007-07-09
Posts: 8
|
if i set static fields i have no problem (see below). But my AD has computers in different OU's So i need to look up the adspath. I have tried a few different methods but have not success. any help on a searcher that works with kix would nice.
Dim $oRootDSE, $sDomainADsPath, $ldapPath, $filter, $entry, $searcher, $result, $DirectoryServices, $objParent $oRootDSE = GetObject("LDAP://RootDSE") $sDomainADsPath = "LDAP://" & $oRootDSE.Get("defaultNamingContext") $ldapPath = $sDomainADsPath $filter = String.Format("(+(objectCategory=computer)(name="+ @WKSTA +"))")
$objParent = GetObject("LDAP://CN=compname,OU=folder1,OU=folder0,DC=domain,DC=com") $objParent.Put("description", "@fullname") $objParent.SetInfo
|
|
Top
|
|
|
|
#177696 - 2007-07-10 05:47 PM
Re: user to computer desc
[Re: Mart]
|
ack2000
Fresh Scripter
Registered: 2007-07-09
Posts: 8
|
will do.
|
|
Top
|
|
|
|
#177699 - 2007-07-10 07:22 PM
Re: user to computer desc
[Re: Les]
|
ack2000
Fresh Scripter
Registered: 2007-07-09
Posts: 8
|
filter was left from failed search, thanks. wasnt able to find TranslateName UDF sample that was mention above.
Dim $oRootDSE, $sDomainADsPath, $ldapPath, $filter, $entry, $searcher, $result, $DirectoryServices, $objParent
$oRootDSE = GetObject("LDAP://RootDSE")
$sDomainADsPath = "LDAP://" + $oRootDSE.Get("defaultNamingContext")
$ldapPath = $sDomainADsPath
$objParent = GetObject("LDAP://CN=softsol000340d,OU=Software_Solutions_Workstations,OU=DCAS,DC=dcas1,DC=com")
$objParent.Put("description", "@fullname")
$objParent.SetInfo
trying to do a record set search but it fails everytime at while not $orecordset.eof
Dim $oRootDSE, $sDomainADsPath, $oCon, $oRecordSet, $oCmd, $sGroup, $sProperties, $aDescription, $aMember, $iCount
$oRootDSE = GetObject("LDAP://RootDSE")
$sDomainADsPath = "LDAP://" & $oRootDSE.Get("defaultNamingContext")
$oCon = CreateObject("ADODB.Connection")
$oRecordSet = CreateObject("ADODB.Recordset")
$oCmd = CreateObject("ADODB.Command")
;$oRootDSE = Nothing
$oCon.Provider = "ADsDSOObject"
$oCon.Open("ADProvider")
$oCmd.ActiveConnection = $oCon
$sProperties = "ADsPath,description"
$sGroup = "*"
$oCmd.CommandText = "<"+$sDomainADsPath+">;(+(objectClass=computer)(cn="+@WKSTA+"));"+$sProperties+";subtree"
$oRecordSet = $oCmd.Execute
;$oRecordSet.MoveFirst
While Not $oRecordSet.EOF ;fails right here
$icount = $oRecordSet.Fields("ADsPath").Value
End While
Dim $oRootDSE, $sDomainADsPath, $ldapPath, $filter, $entry, $searcher, $result, $DirectoryServices, $objParent
$oRootDSE = GetObject("LDAP://RootDSE")
$sDomainADsPath = "LDAP://" + $oRootDSE.Get("defaultNamingContext")
$ldapPath = $sDomainADsPath
$filter = String.Format("(+(objectCategory=computer)(name="+ @WKSTA +"))")
$objParent = GetObject("$icount")
$objParent.Put("description", "@fullname")
$objParent.SetInfo
$oRecordSet.Close
$oCon.Close
$oRecordSet = Nothing
$oCon = Nothing
Edited by ack2000 (2007-07-10 07:28 PM)
|
|
Top
|
|
|
|
#177702 - 2007-07-10 09:18 PM
Re: user to computer desc
[Re: Les]
|
ack2000
Fresh Scripter
Registered: 2007-07-09
Posts: 8
|
working code: takes user name and windows version and places it in the AD computer description.
$Names = TranslateName (3, "", 3, @Domain + "\" + @wksta + "$", "1")
Dim $x
$objParent = GetObject("LDAP://" + $Names[1])
$objParent.Put("description",""+@fullname+ " " +@PRODUCTTYPE+"")
$objParent.SetInfo
Function TranslateName ($InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType)
Dim $NameTranslate, $Error, $ErrorText, $ReturnNameArray[12], $GetNameArray, $value
$Error = 0
$ErrorText = ""
$ReturnName = ""
$NameTranslate = CREATEOBJECT ("NameTranslate")
$Error = @error
$ErrorText = @serror
if $Error = 0
$NameTranslate.Init ($InitType, $BindName)
$Error = @error
$ErrorText = @serror
if $Error = 0
$NameTranslate.Set ($LookupNameType, $LookupName)
$Error = @error
$ErrorText = @serror
if $Error = 0
Dim $index
$GetNameArray = split($ReturnNameType, ",")
for $index=0 to ubound($GetNameArray)
$value = $GetNameArray[$index]
$ReturnNameArray[$value] = $NameTranslate.Get($value)
next
else
WriteLog("TranslateName SET Error: (" + $Error + ") " + $ErrorText)
exit $Error
endif
else
WriteLog("TranslateName INIT Error: (" + $Error + ") " + $ErrorText)
exit $Error
endif
else
WriteLog("TranslateName CREATEOBJECT Error: (" + $Error + ") " + $ErrorText)
exit $Error
endif
$TranslateName = $ReturnNameArray
Exit 0
Endfunction
|
|
Top
|
|
|
|
#177703 - 2007-07-10 09:26 PM
Re: user to computer desc
[Re: Les]
|
ack2000
Fresh Scripter
Registered: 2007-07-09
Posts: 8
|
kix is what we a currently using for login script. so I am only changing what I need to right now. the reason for this it attempt to see how many non exist computer are floating around in AD (just recently start working here) and there are more computer names the actual users....So its a user script and i was going to attempt to spefiy the admin, password in the getobject of the code. this way I wont have to worry about permissions. This only temporary anyways.
|
|
Top
|
|
|
|
#177704 - 2007-07-10 09:31 PM
Re: user to computer desc
[Re: ack2000]
|
ack2000
Fresh Scripter
Registered: 2007-07-09
Posts: 8
|
permission were not an issue. Just tested with Domain user and it updated the Description. This might be a flaw in the this domains AD. I will have to research.
BTW Thank you for all your help.
Edited by ack2000 (2007-07-10 09:42 PM)
|
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
0 registered
and 1539 anonymous users online.
|
|
|