Skip to content

Commit

Permalink
Create powershell-examples.md
Browse files Browse the repository at this point in the history
  • Loading branch information
dgosbell committed Jul 28, 2024
1 parent 4f43c41 commit 4362dda
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions docs/features/command-line/powershell-examples.md
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
}
```

0 comments on commit 4362dda

Please sign in to comment.