TabularEditor
TabularEditor copied to clipboard
Execute C# script from comand line using powershell
Hi @otykier I've a similar Issue with TE2. I've a C# script that works ok using the GUI but I'm not be able to execute it using this power shell script:
# Definir los valores de los parámetros
$ServerName = "My Azure AS"
$DatabaseName = "my DB"
$UserName = "my user"
$PasswordFile = "C:\SYSTEM\UCCE\MyPassword.xml"
$ScriptType ="Csharp"
$ScriptPath = "C:\SYSTEM\UCCE\SetCustomdataRLS.csx"
$TabularEditorPath = "C:\Program Files (x86)\Tabular Editor"
$LogFilePath = "C:\SYSTEM\UCCE\TabularEditorLog.txt"
# Obtener la contraseña del archivo cifrado
$SecurePassword = Get-Content $PasswordFile | ConvertTo-SecureString
$Password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePassword))
# Crear una cadena de conexión para conectarse a Azure Analysis Services
$ConnectionString = "Provider=MSOLAP;Data Source=$ServerName;Initial Catalog=$DatabaseName;User ID=$UserName;Password=$Password;"
& "$TabularEditorPath\TabularEditor.exe" $ConnectionString -S $ScriptPath
Can you help me? Thanks in advance
Originally posted by @rvgfox in https://github.com/TabularEditor/TabularEditor3/issues/123#issuecomment-1513479978
Moving this issue to the TE2 repo
Hi @otykier Some news?
What error message are you seeing?
@otykier I do not receive any error message, the only thing is that the csx script that I pass as a parameter is not executed. If I use the line:
& "$TabularEditorPath\TabularEditor.exe" $ConnectionString
Without the script, tabular editor opens connected to the SSAS model...
You’re not instructing the CLI to save the model after script execution. You would have to add the -B switch for that. If that is intentional, how do you know the script has not been exrcuted?
Sorry, -D switch is to save the changes back to Analysis Services/Power BI. -B is for saving as a .bim
@otykier I'm sure because if I open and run the script using the GUI I can see that it works, but if I use the command line nothing happens. What will be exactly the command line instruction?
What is the purpose of the script? If your script is modifying the model, for example adding new measures, then the command you’re using will appear not to do anything, since TE is just loading the model and running the script, and then exiting.
If you want TE to save the model after the script has executed, you should add -D
to the end of the command.
The script it's "simple". It's adds an additional condition to the filterexpression in the existing roles. It runs ok directly in the GUI but I need to run it using the commad line from my powershell script.
@otykier I've tried with:
& "$TabularEditorPath\TabularEditor.exe" $ConnectionString -S $ScriptPath -D
And it doesn't works
What does the command line output? If there was an error, you should see it in the output from the command. If you don’t see any output, you may need to change the way you’re calling TabularEditor.exe (sorry, I’m not a PowerShell expert - I usually recommend running the TE2 CLI from a regular window command line).
Maybe this helps: https://stackoverflow.com/a/1742758
Another way to try to debug the issue, is if you add a line to your script, Info("hello");
which you should see as output when the script is being executed from CLI.
@otykier Can you give me an example of the command line using TE2 CLI?
Ah shoot - only now did I notice that you only specify 1 parameter before the -S switch. You need to specify both the connection string and the database name as two separate parameters (when only the connection string parameter is specified, the command will only work if the endpoint contains exactly 1 database)
In windows CLI, it would look like this:
start /wait tabulareditor.exe "Provider=MSOLAP;Data Source=…" "AdventureWorks" -S "c:\path\to\scriptfile.csx" -D
Hi @otykier I've detected that the problem it's in the csx script, but I don't understand why.
My workaround it's:
- Open the model with TE3
- Apply the changes with the script csx
- Save as bim file
- Apply the changes to the model using the command line with TE2