Export-CMQuery

Export a query from Configuration Manager.

Syntax

Export-CMQuery
      [-Comment <String>]
      -ExportFilePath <String>
      -Name <String>
      [-DisableWildcardHandling]
      [-ForceWildcardHandling]
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]
Export-CMQuery
      [-Comment <String>]
      -ExportFilePath <String>
      -Id <String>
      [-DisableWildcardHandling]
      [-ForceWildcardHandling]
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]
Export-CMQuery
      [-Comment <String>]
      -ExportFilePath <String>
      [-InputObject] <IResultObject>
      [-DisableWildcardHandling]
      [-ForceWildcardHandling]
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]

Description

Use this cmdlet to export a query from Configuration Manager. Configuration Manager queries define a WMI Query Language (WQL) expression to get information from the site database based on the criteria you provide.

You can export a query to copy it from one site to another. For example, to copy a query from a test lab to a production environment.

Configuration Manager exports the query to a managed object format (MOF) file. You can then use the Import-CMQuery cmdlet to import the query to another site.

For more information, see Introduction to queries in Configuration Manager.

Note

Run Configuration Manager cmdlets from the Configuration Manager site drive, for example PS XYZ:\>. For more information, see getting started.

Examples

Example 1: Export a query

This command exports a query called My systems to an exported file called query.mof.

Export-CMQuery -Name "My systems" -ExportFilePath "C:\export\query.mof"

Example 2: Export a query with a comment

This example sets a comment in the exported file.

Export-CMQuery -Name "My Systems" -ExportFilePath "C:\Export\Query.mof" -Comment "This is a comment"

// Comments :
//
// This is a comment

Parameters

-Comment

Specify an optional comment. Configuration Manager includes the comment in the MOF file. If you use the Configuration Manager console to import the query, the comment displays in the Import Objects Wizard.

This comment has a limit of 1024 characters.

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Confirm

Prompts you for confirmation before running the cmdlet.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-DisableWildcardHandling

This parameter treats wildcard characters as literal character values. You can't combine it with ForceWildcardHandling.

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-ExportFilePath

Specify the path to the exported file. The file extension is .mof. It can be a local or network path. Create the target folder first.

Type:String
Aliases:FileName, FilePath, Path
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-ForceWildcardHandling

This parameter processes wildcard characters and may lead to unexpected behavior (not recommended). You can't combine it with DisableWildcardHandling.

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Id

Specify the ID of the query to export. For example, XYZ00006.

Type:String
Aliases:QueryId
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-InputObject

Specify a query object to export. To get this object, use the Get-CMQuery cmdlet.

Type:IResultObject
Aliases:Query
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-Name

Specify the name of the query to export.

Type:String
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet doesn't run.

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

Inputs

Microsoft.ConfigurationManagement.ManagementProvider.IResultObject

Outputs

System.Object