VBScript 中的列表 [英] Lists in VBScript
问题描述
我正在尝试在 VBscript 中创建一个简单的列表,但找不到类似的内容.
I'm trying to create a simple list in a VBscript, but I'm unable to find something similar.
基本上,我正在处理 Active Directory,我需要为域中的所有用户获取用户所属的所有组.现在,每个用户可能是不同数量组的成员,所以我计划使用字典,键是用户的 SAMID,值是他/她所属的所有组的列表.
Basically, I'm working on Active directory, and I need to get all the groups a user is a member of for all the users within a domain. Now, every user might be a member of a different number of groups, so I plan to use a dictionary, with the key being the SAMID for the user, and the value being a list of all the groups he/she is a member of.
我可以用静态数组来做到这一点,但是我必须为数组声明一个随机的大尺寸,这不太好.理想情况下,我想做的是一个类似 python 的列表,我可以在其中简单地执行 myList.Add 之类的操作,而不必担心大小问题.
I can do this with a static array, but then I have to declare a random large size for the array which is not nice. What I would ideally like to do is have a python-like list, where I can simple do something like myList.Add and don't have to worry about sizing.
我尝试使用 System.Collection.ArrayList,但运行时出现错误:
I tried using System.Collection.ArrayList, but I get an error when I run it:
PS C:\tmp> cscript.exe .\foo.vbs
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
C:\tmp\foo.vbs(1, 1) (null): 0x80131700
我怎样才能做到这一点?
how can I accomplish this?
推荐答案
Set dic = CreateObject("Scripting.Dictionary")
dic.Add "Item1", ""
dic.Add "Item2", ""
dic.Add "Item3", ""
这篇关于VBScript 中的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!