Delen via


Invoke-ASCmd

Enables database administrators to execute an XMLA script, TMSL script, Data Analysis Expressions (DAX) query, Multidimensional Expressions (MDX) query, or Data Mining Extensions (DMX) statement against an instance of Analysis Services.

Syntax

Invoke-ASCmd
      [-ProgressAction <ActionPreference>]
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]
Invoke-ASCmd
      [-Database <String>]
      [-Query <String>]
      [-ConnectionString <String>]
      [-QueryTimeout <Int32>]
      [-ConnectionTimeout <Int32>]
      [-TraceFile <String>]
      [-Variables <String[]>]
      [-TraceTimeout <Int32>]
      [-TraceLevel <TraceLevelOption>]
      [-TraceFileFormat <TraceFileFormatOption>]
      [-TraceFileDelimiter <String>]
      [-Server <String>]
      [-Credential <PSCredential>]
      [-ServicePrincipal]
      [-ApplicationId <String>]
      [-TenantId <String>]
      [-CertificateThumbprint <String>]
      [-ProgressAction <ActionPreference>]
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]
Invoke-ASCmd
      [-Database <String>]
      [-ConnectionString <String>]
      [-InputFile <String>]
      [-QueryTimeout <Int32>]
      [-ConnectionTimeout <Int32>]
      [-TraceFile <String>]
      [-Variables <String[]>]
      [-TraceTimeout <Int32>]
      [-TraceLevel <TraceLevelOption>]
      [-TraceFileFormat <TraceFileFormatOption>]
      [-TraceFileDelimiter <String>]
      [-Server <String>]
      [-Credential <PSCredential>]
      [-ServicePrincipal]
      [-ApplicationId <String>]
      [-TenantId <String>]
      [-CertificateThumbprint <String>]
      [-ProgressAction <ActionPreference>]
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]
Invoke-ASCmd
      [-Server <String>]
      [-Credential <PSCredential>]
      [-ServicePrincipal]
      [-ApplicationId <String>]
      [-TenantId <String>]
      [-CertificateThumbprint <String>]
      [-ProgressAction <ActionPreference>]
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]
Invoke-ASCmd
      [-Server <String>]
      [-Credential <PSCredential>]
      [-ServicePrincipal]
      [-ApplicationId <String>]
      [-TenantId <String>]
      [-CertificateThumbprint <String>]
      [-ProgressAction <ActionPreference>]
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]

Description

Enables database administrators to execute an XMLA script, TMSL script, Data Analysis Expressions (DAX) query, Multidimensional Expressions (MDX) query, or Data Mining Extensions (DMX) statement against an instance of Analysis Services.

The cmdlets execution of these queries or scripts within input files.

The script that is passed is an XMLA command and following commands are supported: Alter, Backup, Batch, BeginTransaction, Cancel, ClearCache, CommitTransaction, Create, Delete, DesignAggregations, Drop, Insert, Lock, MergePartitions, NotifyTableChange, Process, Restore, RollbackTransaction, Statement (used to execute MDX queries and DMX statements), Subscribe, Synchronize, Unlock, Update, UpdateCells.

This script will also accept JSON commands designed to execute against a tabular database with compatibility mode 1200 or higher.

Module requirements: version 21+ on PowerShell 5.1; version 21 (recent preview) or version 22+ on PowerShell 7.x.

Examples

Invoke discover

Invoke-ASCmd -Server:localhost -Query "<Discover xmlns='urn:schemas-microsoft-com:xml-analysis'><RequestType>DBSCHEMA_CATALOGS</RequestType><Restrictions /><Properties /></Discover>"

Invoke discover 2

Invoke-ASCmd -Database "Adventure Works DW 2008R2" -Query "<Discover xmlns='urn:schemas-microsoft-com:xml-analysis'><RequestType>DISCOVER_DATASOURCES</RequestType><Restrictions></Restrictions><Properties></Properties></Discover>"

Invoke select

Invoke-ASCmd -Database "Adventure Works DW 2008R2" -Query "SELECT {[Measures].[Internet Sales Amount]} ON COLUMNS, BOTTOMCOUNT(NONEMPTY(DESCENDANTS( [Customer].[Customer Geography].[All Customers], [Customer].[Customer Geography].[Customer]), ( [Measures].[Internet Sales Amount] ) ), 10, ( [Measures].[Internet Sales Amount] )) ON ROWS FROM [Adventure Works] WHERE ( [Date].[Calendar].[Calendar Year].&[2008] )"

Invoke select 2

Invoke-ASCmd -Database "Adventure Works DW 2008R2" -Query "SELECT MODEL_CATALOG, MODEL_NAME, ATTRIBUTE_NAME, NODE_NAME FROM [Forecasting].CONTENT"

Invoke with xmla file

Invoke-ASCmd -InputFile C:\MyFolder\DiscoverConnections.xmla

<# DiscoverConnections.xmla is as follows:

 <Discover xmlns="urn:schemas-microsoft-com:xml-analysis">
   <RequestType>DISCOVER_CONNECTIONS</RequestType>
   <Restrictions />
   <Properties>
     <PropertyList>
       <Content>Data</Content>
     </PropertyList>
   </Properties>
 </Discover>

#>

Parameters

-ApplicationId

The application Id for the service principal.

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

-CertificateThumbprint

The certificate thumbprint for the service principal.

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

-ConnectionString

Specifies the connection string.

Note that other connection-level properties like Server, Database, etc. are ignored when this property is specified and therefore these properties must be included in the connection string.

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

-ConnectionTimeout

Specifies the number of seconds before the connection to the Analysis Services instance times out. The timeout value must be an integer between 0 and 65534. If 0 is specified, connection attempts do not time out.

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

-Credential

If this parameter is specified, the user name and password passed will be used to connect to specified Analysis Server instance. If no credentials are specified default windows account of the user who is running the tool will be used.

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

-Database

Specifies the database against which an MDX query or DMX statement will execute. The database parameter is ignored when the cmdlet executes an XMLA script, because the database name is embedded in the XMLA script.

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

-InputFile

Identifies the file that contains the XMLA script, MDX query, DMX statement, or TMSL script (in JSON). You must specify a value for either the InputFile or the *Query *parameter when using Invoke-AsCmd.

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

-ProgressAction

Determines how PowerShell responds to progress updates generated by a script, cmdlet, or provider, such as the progress bars generated by the Write-Progress cmdlet. The Write-Progress cmdlet creates progress bars that show a command's status.

Type:ActionPreference
Aliases:proga
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Query

Specifies the actual script, query, or statement directly on the command line instead of in a file.

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

-QueryTimeout

Specifies the number of seconds before the queries time out. If a timeout value is not specified, the queries do not time out. The timeout must be an integer between 1 and 65535.

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

-Server

Optionally specifies the server instance to connect to if not currently in the SQLAS Provider directory.

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

-ServicePrincipal

Specifies that this connection is using service principal.

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

-TenantId

The tenant Id for the service principal.

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

-TraceFile

Identifies a file that receives Analysis Services trace events while executing the XMLA script, MDX query, or DMX statement. If the file already exists, it is automatically overwritten (except for the trace files that are created by using the -TraceLevel:Duration and -TraceLevel:DurationResult parameter settings).

File names that contain spaces must be enclosed in quotation marks ("").

If the file name is not valid, an error message is generated.

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

-TraceFileDelimiter

Specifies a single character as the trace file delimiter when you specify csv as the format for the trace file that use the -TraceFileFormat parameter.

Default is | (pipe, or vertical bar).

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

-TraceFileFormat

Specifies the file format for the -TraceFile parameter (if this parameter is specified).

The default value is "Csv".

Type:TraceFileFormatOption
Accepted values:Csv, Text
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-TraceLevel

Specifies what data is collected and recorded in the trace file. Possible values are High, Medium, Low, Duration, DurationResult.

Type:TraceLevelOption
Accepted values:High, Medium, Low, Duration, DurationResult
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-TraceTimeout

Specifies the number of seconds the Analysis Services engine waits before ending the trace (if you specify the -TraceFile parameter).

The trace is considered finished if no trace messages have been recorded during the specified time period.

The default trace time-out value is 5 seconds.

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

-Variables

Specifies additional scripting variables. Each variable is a name- value pair. If the value contains embedded spaces or control characters, it must be enclosed in double-quotation marks. Use a PowerShell array to specify multiple variables and their values.

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

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

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

Inputs

PSObject

Outputs

string

Notes

Supported on all Analysis Services instances including PowerBI Premium