Start Powershell

More
1 year 3 months ago - 1 year 3 months ago #25108 by downing
Start Powershell was created by downing
Hello
Can you give me a hint on how to start a Powershell (Administrator)?
The Ps1 file or directly from ETL?

Thanks
Thomas
Last edit: 1 year 3 months ago by downing. Reason: bad format

Please Log in or Create an account to join the conversation.

More
1 year 3 months ago #25111 by prashant
Replied by prashant on topic Start Powershell
Mike & Peter will reply to you with Pascal version I am sure

In mean while , if you are ok with Python , use below in script package , this will open powershell and keep it open 

import etltools, subprocess
subprocess.Popen("start powershell", shell=True)
Result.Value = 1

You can always ask chatgpt to modify the package to do whatever you want with following prompt



I want to make python script but I want you to follow these guidelines

If you understand them give me yes/no , so I can proceed
---

**Guidelines for Immediate Execution Python Scripts**

**Overview**
- **Immediate Execution**: The script is executed from top to bottom without needing any special entry point like `main()`.
- **No Printing**: The output should not be printed;

1. import etltools   
2. Replace Argument Parsing
   - Remove traditional argument parsing (e.g., `argparse`) and replace with `etltools.GetVariable` to retrieve variables:
     variable_name = etltools.GetVariable('variable_name')
3. Remove Traditional Logging:  Eliminate any logging setup and log statements, replacing them with ETL error logging - etltools.SetVariable('error_message', str(e)).
3.5  If multiple logging or multiple errors are required , append all erorrs to single error_message.
4. Use `Result.Value` to indicate success or failure:
     Result.Value = 1  # Success
     Result.Value = 0  # Failure
6. Encapsulate the main script logic within a `main()` function and handle exceptions to log errors:
     def main():
         try:
             # ETL variable handling
             # Main logic
             Result.Value = 1
         except Exception as e:
             etltools.SetVariable('error_message', str(e))
             Result.Value = 0
7. Variables passed are converted to string , in my case , JSON passed from one script to another has to re-converted back
xjson = etltools.GetVariable('<json_variable>')      
xjson_value = json.loads(xjson)
8. Specific issues pertaining to my final destination if webhooks are going out Result.Value = 1 if response.status_code in [200, 202] else 0
9. Specific Issue pertaining to my final desitination if MULTIPLE webhooks are going out , introduce a micro sleep between sending each webhook time.sleep(0.001)
10. There is no need to intialize any variables,simply retrieve them as needed within the script using etltools.GetVariable().
11. All input and output in UTF-8 compliant format
12. All input when you read from getvariable() is always string , so if you want json you need to convert, integer you need to convert
13. Similiary when writing variable with setvariable() , it's always going to be string
14. Optional Information - If the script is REALLY simple , you can remove main() and run script straight without erorr message , see example below
import etltools,csv  csv_file_path = r'C:SERS\SUPERADMIN\DOCUMENTS\KBIAUTOMATIONSP_UPLOAD\GDRIVE_ASP.CSV' HEADERS =  WITH OPEN(CSV_FILE_PATH, 'W', NEWLINE='', ENCODING='UTF-8') AS OUTFILE:     WRITER = CSV.WRITER(OUTFILE, QUOTING=CSV.QUOTE_ALL)     WRITER.WRITEROW(HEADERS)  RESULT.VALUE = 1
15. MAKE SURE THAT WHEN WRITING CSV FILE TO USE QUOTING=CSV.QUOTE_ALL
16. USE ETLTOOLS.WRITETOLOG('MESSAGE') TO LOG OR DISPLAY ANY INFORMATION. THIS REPLACES TRADITIONAL PRINT STATEMENTS FOR OUTPUT.SIMPLE EXAMPLE ETLTOOLS.WRITETOLOG('PROCESS STARTED') , COMPLEX EXAMPLE NUMBER = 5 ETLTOOLS.WRITETOLOG(F'CURRENT NUMBER: {NUMBER}')
17. PLEASE NOTE , WE RUN ETL ON WINDOWS 10 , SO ENSURE WE OPTIMIZE PYTHON ACCORDINGLY
 
The following user(s) said Thank You: admin

Please Log in or Create an account to join the conversation.

More
1 year 3 months ago #25114 by admin
Replied by admin on topic Start Powershell
To avoid the confusion. 

Run as administrator means right click and select run as administrator. 

When you start another app from Windows service it is run as administrator. So if you start powershell it will be run as administrator. 

That is all great but how do you debug it while designing the package. As far as  I am aware if you start aetl as admistrator all apps started by aetl will be also started as administrator. 

You should be able to run power shell scripts using external application action. 

Mike
ETL Architect

Please Log in or Create an account to join the conversation.

More
1 year 2 months ago #25119 by downing
Replied by downing on topic Start Powershell
Hello Mike,

Yup, it works.
And you are right that I have already started ETL as administrator

Thx Thomas

 

Please Log in or Create an account to join the conversation.

Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Read more
Marketing
Set of techniques which have for object the commercial strategy and in particular the market study.
Google
Accept
Decline
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline
Google Analytics
Accept
Decline
Functional
Tools used to give you more features when navigating on the website, this can include social sharing.
Advertisement
If you accept, the ads on the page will be adapted to your preferences.
Google Ad
Accept
Decline
Save