Vbscript 如何向广告用户写入4个属性?
脚本应执行以下操作:Vbscript 如何向广告用户写入4个属性?,vbscript,Vbscript,脚本应执行以下操作: 读取CSV文件:文件中每个用户有5个数据,数据用“;”解析。每行Sp 5数据,例如:aleroy;4181234567;2345678;;; 你可以有这样一行:aleroy 只有在文件中有数据时才会写入数据(第一个显然不算,因为它是广告用户名) 就像我说的,如果文件中有数据,它将覆盖广告中的数据,否则,它将循环到下一个用户 我不是一个程序员,所以我有很多问题使它工作。我已经纠正了一些错误,.vbs现在运行正常,但没有在我的广告中写入任何内容 这是我制作的完整脚本 Const
aleroy;4181234567;2345678;;;代码>
你可以有这样一行:aleroy代码>
只有在文件中有数据时才会写入数据(第一个显然不算,因为它是广告用户名)
Const FLAT_FILE_DELIMITER = ";"
Const ForReading = 1 'les modes d'ouverture possible du fichier
Const sdnDC = "DC=03QS,DC=LOCAL"'pour identifier le nom de domaine vers lequel on veut importer
Dim adoCSVConnection, adoCSVRecordSet, strPathToTextfile
'Où se trouve le fichier d'export
Dim FlatFilePath: FlatFilePath = "C:\ImportBottin.csv"
Dim strCSVFile
Dim FileSystem
Dim LigneCI
dim username, mobile, pager, telephonenumber, fax
'***************************************************************************
'On s'assure que le fichier de résultats a bien été généré et transféré
Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")
If FileSystem.FileExists(FlatFilePath) = FALSE then
Set FileSystem = Nothing
WScript.quit()
End if
'***************************************************************************
' Specify CSV file name.
Set objTextFile = FileSystem.OpenTextFile(FlatFilePath, ForReading)
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
'***************************************************************************
Do While objTextFile.AtEndOfStream <> true
LigneCI = objTextFile.Readline
p1=Instr (LigneCI, FLAT_FILE_DELIMITER)
if p1 > 0 then
arr = Split(LigneCI, FLAT_FILE_DELIMITER)
If UBound(arr) = 4 Then
username = arr(0)
mobile = arr(1)
pager = arr(2)
telephonenumber = arr(3)
fax = arr(4)
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = "<LDAP://"& sdnDC & _
">;(&(objectCategory=person)(objectClass=user)(userPrincipalName="& _
username &"));mobile,pager,telephonenumber,facsimileTelephoneNumber;subtree"
UpdateAD objCommand, mobile, pager, telephonenumber, fax
Else
WScript.Echo "ligne en erreur : " & csTR(LigneCI)
End If
end if
Loop
Sub UpdateAD (objAD,Cell,Page,Tel,Fax)
'Permet d'envoyer le bon attribut AD à la méthode AjoutAttribut
if not (Tel = "" or Tel = "NULL") then
AjoutAttribut objAD,"telephonenumber", Tel
end if
if not (Cell = "" or Cell = "NULL") then
AjoutAttribut objAD,"mobile",Cell
end if
if not (Page = "" or Page = "NULL") then
AjoutAttribut objAD,"pager",Page
end if
if not (Fax = "" or Fax = "NULL")then
AjoutAttribut objAD,"facsimileTelephoneNumber",Fax
end if
end sub
Sub AjoutAttribut (Obj,nomAttribut,Attribut)
'Méthode qui ajoute une valeur d'attribut à un objet de l'AD
On Error Resume Next
Err.Number=0
AttributAct=Obj.get(nomAttribut)
if strComp(Attribut,AttributAct,1)<>0 and Attribut <> "" and Attribut <> "NULL" then
Obj.Put nomAttribut,Attribut
end if
if Attribut <> "" and not isnull(Attribut) then
Obj.Put nomAttribut,Attribut
end if
end sub
Const FLAT_FILE_DELIMITER=“;”
读数常数=1'可能的垂直模式
Const sdnDC=“DC=03QS,DC=LOCAL”'veut进口商的域名
Dim adoCSVConnection、adoCSVRecordSet、strPathToTextfile
“Oùse trouve le fichier d”出口
Dim FlatFilePath:FlatFilePath=“C:\ImportBottin.csv”
Dim STRCSV文件
Dim文件系统
暗木犀
dim用户名、手机、寻呼机、电话号码、传真
'***************************************************************************
“关于苏丹的宗教信仰和宗教变革”
设置FileSystem=WScript.CreateObject(“Scripting.FileSystemObject”)
如果FileSystem.FileExists(FlatFilePath)=FALSE,则
设置文件系统=无
WScript.quit()
如果结束
'***************************************************************************
'指定CSV文件名。
设置objTextFile=FileSystem.OpenTextFile(FlatFilePath,ForReading)
设置objConnection=CreateObject(“ADODB.Connection”)
打开“Provider=ADsDSOObject;”
'***************************************************************************
当objTextFile.AtEndOfStream为true时执行此操作
LigneCI=objTextFile.Readline
p1=指令(LINGECI,平面文件分隔符)
如果p1>0,则
arr=拆分(LigneCI,平面文件分隔符)
如果UBound(arr)=4,则
用户名=arr(0)
移动设备=arr(1)
寻呼机=arr(2)
电话号码=arr(3)
传真=arr(4)
设置objCommand=CreateObject(“ADODB.Command”)
objCommand.ActiveConnection=objConnection
objCommand.CommandText=“;(&(objectCategory=person)(objectClass=user)(userPrincipalName=“&”_
用户名(“”);手机、寻呼机、电话号码、传真机电话号码;子树“
更新objCommand、手机、寻呼机、电话号码、传真
其他的
Echo“ligne en erreur:”和csTR(LigneCI)
如果结束
如果结束
环
子更新标题(objAD、单元格、页码、电话、传真)
“我们的外交使节”是一种宗教信仰
如果不是(Tel=”“或Tel=“NULL”),则
AjoutAttribute objAD,“电话号码”,电话:
如果结束
如果不是(Cell=”“或Cell=“NULL”),则
AjoutAttribute objAD,“手机”,手机
如果结束
如果不是(Page=”“或Page=“NULL”),则
AjoutAttribute objAD,“寻呼机”,第页
如果结束
如果不是(Fax=”“或Fax=“NULL”),则
AjoutAttribute objAD,“传真机”,传真
如果结束
端接头
子属性(对象、非属性、属性)
“我的方法是你的财产,而不是你的财产。”
出错时继续下一步
错误号=0
attributeact=Obj.get(noAttribute)
如果strComp(attribute,attributeact,1)0,attribute“”和attribute“NULL”,则
对象放在noattribut,Attribut
如果结束
如果attribute“”且不为null(attribute),则
对象放在noattribut,Attribut
如果结束
端接头
将ADO命令对象传递给子例程,然后尝试调用Get
和Put
。这不起作用(不过,您看不到错误,因为您使用了“错误恢复下一步”)来抑制它)
您需要执行
AD查询以实际检索用户/属性,然后迭代返回的列表:
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = "<LDAP://"& sdnDC & _
">;(&(objectCategory=person)(objectClass=user)(userPrincipalName="& _
username &"));mobile,pager,telephonenumber,facsimileTelephoneNumber;subtree"
Set rs = objCommand.Execute
Do Until rs.EOF
UpdateAD rs, mobile, pager, telephonenumber, fax
rs.MoveNext
Loop
您可能想看看ActiveXperts。它们将帮助您了解这些东西是如何工作的。非常感谢您的帮助。这个周末我会更深入地看一看。我会通知你的,再次感谢你。非常感谢
Set user = GetObject("LDAP://" & rs.Fields("distinguishedName").Value)
user.Put "mobile", "555-1234"
user.SetInfo