run python in powershell windows code example

Example 1: install python windows powershell

You could download the setup you want to install and then install it automatically without using the setup's UI:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Invoke-WebRequest -Uri "https://www.python.org/ftp/python/3.7.0/python-3.7.0.exe" -OutFile "c:/temp/python-3.7.0.exe"

c:/temp/python-3.7.0.exe /quiet InstallAllUsers=0 PrependPath=1 Include_test=0
I don't think it will work without admin privileges though, I tried using InstallAllUsers=0 to install it only for the current user but it is still asking for elevation.

There are some options you can use when installing it this way, here is the doc: https://docs.python.org/3.6/using/windows.html#installing-without-ui

Example 2: run python script powershell

First confirm that you have a file that has some python code in it.
I will assume that the file name is called file.py (for simplicity) 
Oh yeah, and this might not work if you have not added python to PATH when you first downloaded it.

Run the script like this:
python file.py