{"content":"<div></div>","rawMetadata":{"metadata":{"_op_canonicalUrlPrefix":"https://learn.microsoft.com/zh-cn/powershell/","_op_gitContributorInformation":{"author":{"display_name":"Banreet Kaur","id":"92906285","name":"Banreet","profile_url":"https://github.com/Banreet"},"contributors":[{"display_name":"Aaron Czechowski","id":"26784733","name":"aczechowski","profile_url":"https://github.com/aczechowski"},{"display_name":"Dan Mabee","id":"40476441","name":"damabe","profile_url":"https://github.com/damabe"},{"display_name":"Jonathan Gao","id":"2213767","name":"mumian","profile_url":"https://github.com/mumian"},{"display_name":"sankethka","id":"16908144","name":"sankethka","profile_url":"https://github.com/sankethka"}],"update_at":"2026/6/25","updated_at_date_time":"2026-06-25T23:16:38.13097Z"},"_path":"module/configurationmanager/invoke-cmquery.json","_rel":"../../","_tocRel":"../sccm-ps/toc.json","apiPlatform":"powershell","author":"Banreet","breadcrumb_path":"/powershell/sccm/bread/toc.json","canonical_url":"https://learn.microsoft.com/zh-cn/powershell/module/configurationmanager/invoke-cmquery?view=sccm-ps","content_git_url":"https://github.com/MicrosoftDocs/sccm-docs-powershell-ref/blob/main/sccm-ps/ConfigurationManager/Invoke-CMQuery.md","default_moniker":"sccm-ps","depot_name":"MSDN.sccm-powershell","description":"运行 Configuration Manager 查询。","document_id":"bd9706c5-4054-9757-4b45-98bb9546cd0f","document_version_independent_id":"3f7a733e-7bad-18e4-14b5-94acc6c3e1a4","external help file":"AdminUI.PS.dll-Help.xml","feedback_product_url":"https://feedbackportal.microsoft.com/feedback/forum/4669adfc-ee1b-ec11-b6e7-0022481f8472","feedback_system":"Standard","git_commit_id":"48cf632fb4b9ad92060012681a500478254de750","gitcommit":"https://github.com/MicrosoftDocs/sccm-docs-powershell/blob/48cf632fb4b9ad92060012681a500478254de750/sccm-ps/ConfigurationManager/Invoke-CMQuery.md","github_contributors":["aczechowski","damabe","mumian","sankethka"],"locale":"zh-cn","manager":"laurawi","Module Name":"ConfigurationManager","monikers":["sccm-ps"],"ms.author":"dannygu","ms.date":"12/29/2020","ms.service":"configuration-manager","ms.subservice":"other","ms.topic":"reference","open_to_public_contributors":true,"original_content_git_url":"https://github.com/MicrosoftDocs/sccm-docs-powershell/blob/live/sccm-ps/ConfigurationManager/Invoke-CMQuery.md","original_content_git_url_template":"{repo}/blob/{branch}/sccm-ps/ConfigurationManager/Invoke-CMQuery.md","PlatyPS schema version":"2.0.0","products":["https://authoring-docs-microsoft.poolparty.biz/devrel/f1499c3b-793f-48c3-a9ce-20285bcc6541"],"site_name":"Docs","title":"Invoke-CMQuery","titleSuffix":"Configuration Manager","uhfHeaderId":"MSDocsHeader-Powershell","updated_at":"2026-06-25 11:16 PM","xrefs":[{"href":"https://learn.microsoft.com/powershell/module/configurationmanager/invoke-cmquery","monikerGroup":"f98fea35b6ac2b0f56c6ee5ec06ffce9","name":"Invoke-CMQuery","schemaType":"PowershellCmdlet","summary":"<p>运行 Configuration Manager 查询。</p>\n","uid":"ConfigurationManager.Invoke-CMQuery"}],"ocv-translation-feedback":true},"_xrefmap":{"ConfigurationManager":{"href":"./","monikerGroup":"f98fea35b6ac2b0f56c6ee5ec06ffce9","name":"ConfigurationManager","schemaType":"PowershellModule","uid":"ConfigurationManager"},"ConfigurationManager.Invoke-CMQuery":{"href":"invoke-cmquery","monikerGroup":"f98fea35b6ac2b0f56c6ee5ec06ffce9","name":"Invoke-CMQuery","schemaType":"PowershellCmdlet","summary":"<p>运行 Configuration Manager 查询。</p>\n","uid":"ConfigurationManager.Invoke-CMQuery"}},"description":"<p>使用此 cmdlet 在 Configuration Manager 站点中运行查询。 Configuration Manager 查询定义 WMI 查询语言 (WQL) 表达式，以便根据提供的条件从站点数据库获取信息。 WQL 类似于 SQL，但仍通过 SMS 提供程序而不是直接访问数据库。 因此，WQL 仍遵循基于角色的访问配置。</p>\n<p>运行查询时，站点将处理 WQL 表达式，并在 PowerShell 中返回结果。 根据 WQL 语句的结构，结果的格式可能会有所不同。</p>\n<p>查询可以返回大多数类型的 Configuration Manager 对象，其中包括计算机、站点、集合、应用程序和清单数据。 有关详细信息，请参阅 <a href=\"/mem/configmgr/core/servers/manage/introduction-to-queries\">Configuration Manager 中的查询简介</a>。</p>\n<div class=\"NOTE\">\n<p>注意</p>\n<p>从 Configuration Manager 站点驱动器运行 Configuration Manager cmdlet，例如 <code>PS XYZ:\\&gt;</code>。 有关详细信息，请参阅 <a href=\"/powershell/sccm/overview\">入门</a>。</p>\n</div>\n","examples":[{"code":"PS XYZ:\\> Get-CMQuery -Id \"SMS012\"\n\nSmsProviderObjectPath          : SMS_Query.QueryID=\"SMS012\"\nComments                       : This site and all its subsites in the ConfigMgr hierarchy\nExpression                     : SELECT SiteCode, SiteName, Version, ServerName FROM sms_siteandsubsites\nLimitToCollectionID            :\nLocalizedCategoryInstanceNames : {}\nName                           : This Site and its Subsites\nQueryID                        : SMS012\nResultAliasNames               : {sms_siteandsubsites, sms_siteandsubsites, sms_siteandsubsites, sms_siteandsubsites}\nResultColumnsNames             : {sms_siteandsubsites.SiteCode, sms_siteandsubsites.SiteName,\n                                 sms_siteandsubsites.Version, sms_siteandsubsites.ServerName}\nTargetClassName                : sms_siteandsubsites\n\nPS XYZ:\\> Invoke-CMQuery -Id \"SMS012\"\n\nSmsProviderObjectPath : SMS_SiteAndSubsites.SiteCode=\"XYZ\"\nServerName            : cmserver.contoso.com\nSiteCode              : XYZ\nSiteName              : Production primary site\nVersion               : 5.00.9043.1000","description":"<p>请注意， <strong>在 Get-CMQuery</strong> cmdlet 的输出中，WQL <strong>表达式</strong> 很简单。 它从单个类中选择四个属性。</p>\n<p>然后，请注意 <strong>Invoke-CMQuery</strong> cmdlet 的输出是一个简单的表。</p>\n","summary":"<p>此示例首先显示 <strong>Get-CMQuery</strong> cmdlet，以显示默认查询 <strong>“此网站”及其子网站</strong>的属性。</p>\n<p>然后，它显示 <strong>Invoke-CMQuery</strong> cmdlet 以运行相同的查询并显示结果。</p>\n","title":"示例 1：查看和运行默认查询"},{"code":"PS XYZ:\\> Get-CMQuery -Id \"XYZ00002\"\n\nSmsProviderObjectPath          : SMS_Query.QueryID=\"XYZ00002\"\nComments                       :\nExpression                     : select SMS_R_System.Name, SMS_R_System.LastLogonUserName,\n                                 SMS_G_System_OPERATING_SYSTEM.Caption from SMS_R_System inner join\n                                 SMS_G_System_OPERATING_SYSTEM on SMS_G_System_OPERATING_SYSTEM.ResourceID =\n                                 SMS_R_System.ResourceId where SMS_G_System_OPERATING_SYSTEM.Caption like \"Microsoft Windows Server 2012%\"\nLimitToCollectionID            : XYZ0025F\nLocalizedCategoryInstanceNames : {}\nName                           : Server 2016\nQueryID                        : XYZ00002\nResultAliasNames               : {SMS_R_System, SMS_R_System, SMS_G_System_OPERATING_SYSTEM}\nResultColumnsNames             : {SMS_R_System.Name, SMS_R_System.LastLogonUserName,\n                                 SMS_G_System_OPERATING_SYSTEM.Caption}\nTargetClassName                : SMS_R_System\n\nPS XYZ:\\> Invoke-CMQuery -Id \"XYZ00002\"\n\n\nSmsProviderObjectPath         : __GENERIC\nSMS_G_System_OPERATING_SYSTEM :\n                                instance of SMS_G_System_OPERATING_SYSTEM\n                                {\n                                        Caption = \"Microsoft Windows Server 2012 R2 Datacenter\";\n                                };\n\nSMS_R_System                  :\n                                instance of SMS_R_System\n                                {\n                                        LastLogonUserName = \"jqpublic\";\n                                        Name = \"millcreek01\";\n                                };","description":"<p>此查询具有一个更复杂的 <strong>表达式</strong> ，用于联接两个类。 然后，查询的结果会更加复杂。</p>\n","summary":"<p>此示例首先演示 <strong>Get-CMQuery</strong> cmdlet，以显示自定义查询的属性。</p>\n<p>然后，它显示 <strong>Invoke-CMQuery</strong> cmdlet 以运行相同的查询并显示结果。</p>\n","title":"示例 2：查看和运行复杂查询"}],"inputs":[{"description":"","name":"<span class=\"no-loc xref\">Microsoft.ConfigurationManagement.ManagementProvider.IResultObject</span>\n"}],"links":[{"href":"export-cmquery","text":"Export-CMQuery"},{"href":"get-cmquery","text":"Get-CMQuery"},{"href":"import-cmquery","text":"Import-CMQuery"},{"href":"new-cmquery","text":"New-CMQuery"},{"href":"remove-cmquery","text":"Remove-CMQuery"},{"href":"set-cmquery","text":"Set-CMQuery"},{"href":"/mem/configmgr/core/servers/manage/introduction-to-queries","text":"Configuration Manager 中的查询简介"}],"module":"ConfigurationManager","name":"Invoke-CMQuery","notes":"","outputs":[{"description":"","name":"<span class=\"no-loc xref\">System.Object</span>\n"}],"parameters":[{"aliases":"cf","defaultValue":"None","description":"<p>提示你在运行 cmdlet 之前进行确认。</p>\n","name":"Confirm","parameterValueGroup":"","position":"Named","type":"<span class=\"no-loc xref\">SwitchParameter</span>\n"},{"aliases":"","defaultValue":"None","description":"<p>此参数将通配符视为文本字符值。 不能将其与 <strong>ForceWildcardHandling</strong> 组合使用。</p>\n","name":"DisableWildcardHandling","parameterValueGroup":"","position":"Named","type":"<span class=\"no-loc xref\">SwitchParameter</span>\n"},{"aliases":"","defaultValue":"None","description":"<p>此参数处理通配符，并可能导致意外行为， (不建议) 。 不能将其与 <strong>DisableWildcardHandling</strong> 组合使用。</p>\n","name":"ForceWildcardHandling","parameterValueGroup":"","position":"Named","type":"<span class=\"no-loc xref\">SwitchParameter</span>\n"},{"aliases":"QueryId","defaultValue":"None","description":"<p>指定要运行的查询的 ID。 例如，<code>&quot;XYZ00006&quot;</code>。</p>\n","isRequired":true,"name":"Id","parameterValueGroup":"","position":"Named","type":"<span class=\"no-loc xref\">String</span>\n"},{"aliases":"","defaultValue":"None","description":"<p>指定要运行的查询对象。 若要获取此对象，请使用 <a href=\"get-cmquery\">Get-CMQuery</a> cmdlet。</p>\n","isRequired":true,"name":"InputObject","parameterValueGroup":"","pipelineInput":true,"position":"Named","type":"<span class=\"no-loc xref\">IResultObject</span>\n"},{"aliases":"","defaultValue":"None","description":"<p>如果查询配置为提示输入限制集合，请使用此参数指定集合 ID。 如果查询的 <strong>LimitToCollectionID</strong> 属性为 <code>&lt;Prompt&gt;</code>，并且运行查询时未包含此参数，则 cmdlet 将失败。</p>\n","name":"LimitToCollectionId","parameterValueGroup":"","position":"Named","type":"<span class=\"no-loc xref\">String</span>\n"},{"aliases":"","defaultValue":"None","description":"<p>指定要运行的查询的名称。</p>\n","isRequired":true,"name":"Name","parameterValueGroup":"","position":"Named","type":"<span class=\"no-loc xref\">String</span>\n"},{"aliases":"wi","defaultValue":"None","description":"<p>显示在 cmdlet 运行时发生的情况。 cmdlet 不会运行。</p>\n","name":"WhatIf","parameterValueGroup":"","position":"Named","type":"<span class=\"no-loc xref\">SwitchParameter</span>\n"}],"schema":"PowershellCmdlet","summary":"<p>运行 Configuration Manager 查询。</p>\n","syntaxes":["Invoke-CMQuery -InputObject <IResultObject> [-LimitToCollectionId <String>] [-DisableWildcardHandling]\n [-ForceWildcardHandling] [-WhatIf] [-Confirm] [<CommonParameters>]","Invoke-CMQuery -Id <String> [-LimitToCollectionId <String>] [-DisableWildcardHandling] [-ForceWildcardHandling]\n [-WhatIf] [-Confirm] [<CommonParameters>]","Invoke-CMQuery [-LimitToCollectionId <String>] -Name <String> [-DisableWildcardHandling]\n [-ForceWildcardHandling] [-WhatIf] [-Confirm] [<CommonParameters>]"],"uid":"ConfigurationManager.Invoke-CMQuery","hideEdit":true,"ms.translationtype":"MT","ms.contentlocale":"zh-cn","loc_version":"2024-08-21T21:18:36.7205003Z","loc_source_id":"Github-72476255#live","loc_file_id":"Github-72476255.live.MSDN.sccm-powershell.sccm-ps/ConfigurationManager/Invoke-CMQuery.md","xrefs":[{"href":"https://learn.microsoft.com/powershell/module/configurationmanager/invoke-cmquery","monikerGroup":"f98fea35b6ac2b0f56c6ee5ec06ffce9","name":"Invoke-CMQuery","schemaType":"PowershellCmdlet","summary":"<p>运行 Configuration Manager 查询。</p>\n","uid":"ConfigurationManager.Invoke-CMQuery"}],"canonical_url":"https://learn.microsoft.com/zh-cn/powershell/module/configurationmanager/invoke-cmquery?view=sccm-ps","_op_canonicalUrl":"https://learn.microsoft.com/zh-cn/powershell/module/configurationmanager/invoke-cmquery?view=sccm-ps"},"pageMetadata":"<meta name=\"description\" content=\"<p>使用此 cmdlet 在 Configuration Manager 站点中运行查询。 Configuration Manager 查询定义 WMI 查询语言 (WQL) 表达式，以便根据提供的条件从站点数据库获取信息。 WQL 类似于 SQL，但仍通过 SMS 提供程序而不是直接访问数据库。 因此，WQL 仍遵循基于角色的访问配置。</p>\n<p>运行查询时，站点将处理 WQL 表达式，并在 PowerShell 中返回结果。 根据 WQL 语句的结构，结果的格式可能会有所不同。</p>\n<p>查询可以返回大多数类型的 Configuration Manager 对象，其中包括计算机、站点、集合、应用程序和清单数据。 有关详细信息，请参阅 <a href=&quot;/mem/configmgr/core/servers/manage/introduction-to-queries&quot;>Configuration Manager 中的查询简介</a>。</p>\n<div class=&quot;NOTE&quot;>\n<p>注意</p>\n<p>从 Configuration Manager 站点驱动器运行 Configuration Manager cmdlet，例如 <code>PS XYZ:\\&amp;gt;</code>。 有关详细信息，请参阅 <a href=&quot;/powershell/sccm/overview&quot;>入门</a>。</p>\n</div>\n\" />\r\n<meta name=\"hideEdit\" content=\"true\" />\r\n<meta name=\"loc_file_id\" content=\"Github-72476255.live.MSDN.sccm-powershell.sccm-ps/ConfigurationManager/Invoke-CMQuery.md\" />\r\n<meta name=\"loc_source_id\" content=\"Github-72476255#live\" />\r\n<meta name=\"loc_version\" content=\"2024-08-21T21:18:36.7205003Z\" />\r\n<meta name=\"module\" content=\"ConfigurationManager\" />\r\n<meta name=\"ms.contentlocale\" content=\"zh-cn\" />\r\n<meta name=\"ms.translationtype\" content=\"MT\" />\r\n<meta name=\"name\" content=\"Invoke-CMQuery\" />\r\n<meta name=\"notes\" content=\"\" />\r\n<meta name=\"schema\" content=\"PowershellCmdlet\" />\r\n<meta name=\"summary\" content=\"<p>运行 Configuration Manager 查询。</p>\n\" />\r\n<meta name=\"syntaxes\" content=\"Invoke-CMQuery -InputObject <IResultObject> [-LimitToCollectionId <String>] [-DisableWildcardHandling]\n [-ForceWildcardHandling] [-WhatIf] [-Confirm] [<CommonParameters>]\" />\r\n<meta name=\"syntaxes\" content=\"Invoke-CMQuery -Id <String> [-LimitToCollectionId <String>] [-DisableWildcardHandling] [-ForceWildcardHandling]\n [-WhatIf] [-Confirm] [<CommonParameters>]\" />\r\n<meta name=\"syntaxes\" content=\"Invoke-CMQuery [-LimitToCollectionId <String>] -Name <String> [-DisableWildcardHandling]\n [-ForceWildcardHandling] [-WhatIf] [-Confirm] [<CommonParameters>]\" />\r\n<meta name=\"uid\" content=\"ConfigurationManager.Invoke-CMQuery\" />\r\n","themesRelativePathToOutputRoot":"_themes/"}