【问题标题】:VBS Retrieve Computer OU from AD and OU Case Statement to Perform ActionVBS 从 AD 和 OU 案例语句中检索计算机 OU 以执行操作
【发布时间】:2014-03-28 15:49:20
【问题描述】:

我有这段来自 ScriptIT 人员的代码。

Set objSysInfo = CreateObject("ADSystemInfo")
strComputer = objSysInfo.ComputerName
Set objComputer = GetObject("LDAP://" & strComputer)
arrOUs = Split(objComputer.Parent, ",")
arrMainOU = Split(arrOUs(0), "=")
wscript.echo arrMainOU(1)

我遇到的问题是 arrMainOU(1) 两次回显 OU。我尝试设置一个简单的测试,但它失败了。我在这里或谷歌上没有看到这个问题。

If arrMainOU(1) = "myOU" Then
wcript.echo "true"
End If

我需要将 arrMainOU(1) 中的 1 个值与包含 OU 字符串的数组进行比较。我需要一个 case 语句,根据它是 OU1 还是 OU2 等执行操作。

不过,我在评估 arrMainOU(1) 时遇到了困难。如果我将值输出到文件,那么它只会写入一个值。

任何帮助将不胜感激 - 谢谢

【问题讨论】:

  • 它在两个消息框中回显OU两次,还是在一个消息框中重复两次相同的值?

标签: vbscript location ou


【解决方案1】:

试试这个代码 sn-p 来理解'SPLIT'函数:

Set objSysInfo = CreateObject("ADSystemInfo")
strComputer = objSysInfo.ComputerName
Set objComputer = GetObject("LDAP://" & strComputer)
arrOUs = Split(objComputer.Parent, ",")
retstring = ""
For ii = LBound( arrOUs) To UBound( arrOUs)
    arrMainOU = Split(arrOUs(ii), "=")
    For jj = LBound( arrMainOU) To UBound( arrMainOU)
        retstring = retstring & "arrOUs(" & CSTR( ii) & ") = " & arrOUs(ii) & vbTab 
        retstring = retstring & "arrMainOU(" & CSTR( jj) & ") = " & arrMainOU(jj) & vbNewLine
    Next
    retstring = retstring & vbNewLine
Next
Wscript.Echo retstring

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多