AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 466185
Accepted
Mr. Lost IT Guy
Mr. Lost IT Guy
Asked: 2013-01-12 06:48:38 +0800 CST2013-01-12 06:48:38 +0800 CST 2013-01-12 06:48:38 +0800 CST

通过 VBScript 导出 SCCM 2007 查询结果

  • 772

我想知道是否可以通过 VBScript 导出 SCCM 2007 查询的结果。如果有任何建议,将不胜感激。

我知道我可以通过 VBScript 通过 SCCM 导出报告,方法是使用报告的 Web 视图并伪造 export=yes 并提交表单。查询可能会发生这样的事情吗?

我最终得到的作为 VBScript 函数的工作代码:

'sccmQueryAsArray
'Returns: results in an array built based on the columns specified in the call of the function
'   parseInto: an array provided by the calling function that will be filled with the SCCM query results
'   sccmSiteServerName: a string representing the sccm site server we are connecting to
'   sccmSiteCode: a string representing the sccm site code we are connecting to
'   columns: a one dimensional array containing the names of the columns you want to the function to create an array for
'   query: the actual full length query that will be passed to WMI object
'       example call: sccmQueryAsArray data,"server1","sit",array("Name","UsergroupName"),"select Name, UsergroupName, WindowsNTDomain from sms_r_usergroup where AgentName = 'SMS_AD_SECURITY_GROUP_DISCOVERY_AGENT'"
'       results in an array "data" being modified to 2 columns and as many rows as is returned by the query the array would look like:
'           (0)(x) where 0 = the first element in the columns row or Name
'           (1)(x) where 1 = the second element in the columns row or UsergroupName
function sccmQueryAsArray( ByRef parseInto, ByVal sccmSiteServerName, ByVal sccmSiteCode, ByVal columns, ByVal query )

redim preserve parseInto(ubound(columns),0) 'the array that the query information will be parsed into and then returned

dim objWMIService: set objWMIService = getObject("winmgmts://" & sccmSiteServerName & "\root\sms\site_" & sccmSiteCode) 'set up the connection string
dim colGroups: set colGroups = objWMIService.ExecQuery(query) 'execute the query and put the results into colGroups

dim z: z = 0
dim objGroup: for each objGroup in colGroups
    dim y: for y = 0 to ubound(columns) step 1
        dim x: x = "objGroup." & columns(y)
        parseInto(y,z) = eval(x)
    next
redim preserve parseInto(ubound(parseInto,1),ubound(parseInto,2)+1): z = z + 1
next

sccmQueryAsArray = parseInto

end function
vbscript
  • 2 2 个回答
  • 2111 Views

2 个回答

  • Voted
  1. Best Answer
    GAThrawn
    2013-01-12T07:36:24+08:002013-01-12T07:36:24+08:00

    为什么不直接在 VBScript 中执行查询?

    您可以在 VBScript 中附加到 SCCM 服务器,并使用 ExecQuery 将 WQL 查询发送到服务器。

    要使用将 SCCM 查询转换为 VBScript 的简单示例,您可能有一个列出所有 AD 安全组的查询。右键单击该查询,单击编辑查询语句,然后单击显示查询语言。

    你应该有这样的东西:

    select Name, UsergroupName, WindowsNTDomain from sms_r_usergroup where AgentName = 'SMS_AD_SECURITY_GROUP_DISCOVERY_AGENT'
    

    现在单击 Show Query Design 并复制您感兴趣的属性名称(即列标题),您应该得到如下列表:

    Name, User Group Name, Domain
    

    select要获取这些列的实际 SQL 列名(特别是其中有空格的列名),只需查看上一步中的 WQL 查询,您可以在命令后看到列名。你现在应该有这样的东西:

    Name, UsergroupName, WindowsNTDomain
    

    现在把所有这些都放到 VBScript 中,比如:

    'Central SCCM Site Server name
    strComputer = "SCCM01"
    
    'Central SCCM Site Code
    strSiteCode = "ABC"
    
    'Set up the connection String
    Set objWMIService = GetObject("winmgmts://" & strComputer & "\root\sms\site_" & strSiteCode)
    
    'Get the info with a query
    Set colGroups = objWMIService.ExecQuery("select Name, UsergroupName, WindowsNTDomain from sms_r_usergroup where AgentName = 'SMS_AD_SECURITY_GROUP_DISCOVERY_AGENT'")
    
    'output the info
    For Each objGroup in colGroups
        Wscript.echo objGroup.Name & ", " & objGroup.UsergroupName & ", " & objGroup.WindowsNTDomain
    Next 
    

    (显然编辑站点服务器和站点代码行以匹配您的环境)。

    • 0
  2. The_Ratzenator
    2013-02-09T21:56:35+08:002013-02-09T21:56:35+08:00

    很棒的帖子。我只是想补充一点,如果您想使用 PowerShell 而不是 VBS,您应该检查一下:

    http://blogs.technet.com/b/manageabilityguys/archive/2009/11/27/more-on-sccm-and-powershell.aspx

    SCCM 2012 内置了 PowerShell,因此无需为新产品执行此操作。

    • 0

相关问题

  • Vista下禁用windows防火墙的脚本

  • 安装错误:无法访问自定义操作的 VBScript 运行时

  • WScript.Sleep 的替代方案

  • 从 vbscript 下载文件?

  • 在远程机器上安装软件?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve