-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
title: PowerShell Examples | ||
--- | ||
|
||
When you combine `dscmd.exe` with powershell you can do some really powerful things like looping through a series of values and outputting a series of files. | ||
|
||
# Example 1 | ||
The following example loops through an array of characters and export rows where the 'Product'[Color] value starts with the specified letter. This shows how you can insert a variable from Powershell into your query and filename dynamically. | ||
|
||
``` | ||
$cmd = "C:\Users\dgosbell\Downloads\DaxStudio_3_1_0_portable\dscmd.exe" | ||
$server = "localhost:50909" | ||
$database = "5389c85e-326d-4e8f-8e42-f2db2fcb98a4" | ||
foreach ($letter in @("B", "R")) | ||
{ | ||
$query = @" | ||
/* START QUERY BUILDER */ | ||
EVALUATE | ||
SUMMARIZECOLUMNS( | ||
'Product'[Category], | ||
'Product'[Color], | ||
'Product'[Model], | ||
Reseller[Business Type], | ||
Customer[Country-Region], | ||
Customer[State-Province], | ||
KEEPFILTERS( FILTER( ALL( 'Product'[Color] ), SEARCH( \`"$letter\`", 'Product'[Color], 1, 0 ) = 1 )), | ||
\`"Total Sales\`", [Total Sales] | ||
) | ||
ORDER BY | ||
'Product'[Category] ASC, | ||
'Product'[Color] ASC, | ||
'Product'[Model] ASC, | ||
Reseller[Business Type] ASC, | ||
Customer[Country-Region] ASC, | ||
Customer[State-Province] ASC | ||
/* END QUERY BUILDER */ | ||
"@ | ||
&$cmd csv c:\temp\test-$letter.csv -s $server -d $database -q $query | ||
} | ||
``` |