1

我正在尝试执行 SMS WMI 查询(现在是 2012 年,以前是 2007 年的 VBS),使用 Get-WMIObject 命令时有时需要长达 20 分钟(海外)和 5-10 分钟(系统在楼下)。我知道如何在 VBS 中进行更快的调用:

        lLocator = CreateObject("WbemScripting.SWbemLocator")

        gService = lLocator.ConnectServer(Form1.strSQLServer, "root/sms/site_" & Form1.strSiteCode)

        'Query for Distribution Points and populate drop down list
        colItems = gService.ExecQuery("select PackageID, SourceNALPath from SMS_PackageStatusDistPointsSummarizer where PackageID='" & listBootImage.SelectedItem.ID & "'")
        For Each objItems In colItems
            ListDistPoint.Items.Add(UCase(Mid(objItems.SourceNALPath, InStr(objItems.SourceNALPath, "\"))))
            If InStr(objItems.SourceNALPath, Mid(Form1.strSQLServer, 1, (InStr(Form1.strSQLServer, ".") - 1))) Then
                ListDistPoint.SelectedIndex = ListDistPoint.Items.Count - 1
            End If
        Next

在 PS 中,这是我正在打的电话:

invoke-command {Get-WmiObject -namespace root\sms\site_<sitecode> -class SMS_PackageStatusDistPointsSummarizer -computername '<compname>' -property "PackageID","SourceNALPath" | where {$_.PackageID -eq '<pkgname>'} |Select PackageID, SourceNALPath}

或这个:

Get-WmiObject -namespace root\sms\site_<sitecode> -class SMS_PackageStatusDistPointsSummarizer -computername '<compname>' -property "PackageID","SourceNALPath" | where {$_.PackageID -eq '<pkgname>'} |Select PackageID, SourceNALPath

两者的速度相同。是否有更好、更理想的方式来执行与 VB 脚本中相同的操作(远程连接、检索信息,然后返回)?VB 脚本明显更快。运行 SCCM 2012 服务器的硬件更好,所以我不认为速度与服务器性能有关。两个数据库也包含相同的站点、系统等。

谢谢您的帮助。

4

1 回答 1

2

尝试这个:

Get-WmiObject -namespace root\sms\site_$sitecode `
              -computername "$compname" `
              -query "select PackageID, SourceNALPath from SMS_PackageStatusDistPointsSummarizer where PackageID='$pkgname'"

使用您的其他 powershell 语句,您正在查询所有内容,然后在本地进行过滤。使用您在 VBS 中运行的 WMI 查询,查询是在服务器端完成的。需要处理的数据更少,而且效率更高。

于 2014-06-02T23:47:43.330 回答