Code
Sign up
Login
New paste
Home
Trending
Archive
English
Deutsch
English
Sign up
Login
New Paste
Browse
# Script Name: PyGo.ps1 # Description: This script checks if Python 3 is already installed on Windows 10/11. # If not, it downloads and installs the latest version, it also supports uninstalling Python if the -Uninstall flag is provided. # # Author: Jan Gebser # Date: 12.11.24 # Version: 1.3.2 # Contact: j.gebser@webservice.digital <# WORKING ON SOME MORE IMPROVEMENTS AND FEATURES - also to fix the following issue below: Get-ExecutionPolicy -List Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine ''' PS C:\Users\WDAGUtilityAccount\Desktop> .\PyGo.ps1 .\PyGo.ps1 : File C:\Users\WDAGUtilityAccount\Desktop\PyGo.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170. At line:1 char:1 + .\PyGo.ps1 + ~~~~~~~~~~ + CategoryInfo : SecurityError: (:) [], PSSecurityException + FullyQualifiedErrorId : UnauthorizedAccess PS C:\Users\WDAGUtilityAccount\Desktop> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine PS C:\Users\WDAGUtilityAccount\Desktop> .\PyGo.ps1 Python is not installed. Proceeding with installation... Downloading Python installer from https://www.python.org/ftp/python/3.13.0/python-3.13.0-amd64.exe... Download complete. Installing Python... Installation complete. Cleaning up... Cleanup complete. Verifying installation... python : The term 'python' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:\Users\WDAGUtilityAccount\Desktop\PyGo.ps1:102 char:22 + $pythonVersion = python --version + ~~~~~~ + CategoryInfo : ObjectNotFound: (python:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException Python installation and verification complete. Installed version: Installation Date: 11/12/2024 10:56:27 Operating System Version: 2004 PS C:\Users\WDAGUtilityAccount\Desktop> .\PyGo.ps1 Python is not installed. Proceeding with installation... Downloading Python installer from https://www.python.org/ftp/python/3.13.0/python-3.13.0-amd64.exe... PS C:\Users\WDAGUtilityAccount\Desktop> ''' #> param ( [switch]$Uninstall ) # Function to check if Python is installed function Check-PythonInstalled { try { $pythonVersion = python --version 2>&1 if ($pythonVersion -match "Python (\d+\.\d+\.\d+)") { return $true, $matches[1] } else { return $false, $null } } catch { return $false, $null } } # Function to get installation statistics function Get-InstallationStats { $installDate = Get-Date $osVersion = (Get-ComputerInfo).WindowsVersion return @{ InstallDate = $installDate OSVersion = $osVersion } } # Function to uninstall Python function Uninstall-Python { Write-Output "Uninstalling Python..." $pythonPath = (Get-Command python).Path $uninstallerPath = Join-Path (Split-Path $pythonPath -Parent) "uninstall.exe" if (Test-Path $uninstallerPath) { Start-Process -FilePath $uninstallerPath -ArgumentList "/quiet" -Wait Write-Output "Python uninstalled successfully." } else { Write-Output "Uninstaller not found. Manual uninstallation may be required." } } # Check if the -Uninstall flag is provided if ($Uninstall) { $pythonInstalled, $installedVersion = Check-PythonInstalled if ($pythonInstalled) { Uninstall-Python } else { Write-Output "Python is not installed." } exit } # Check if Python is already installed $pythonInstalled, $installedVersion = Check-PythonInstalled if ($pythonInstalled) { Write-Output "Python is already installed." Write-Output "Version: $installedVersion" Write-Output "Installation path: $(Get-Command python).Path" } else { Write-Output "Python is not installed. Proceeding with installation..." # Define the URL for the latest Python 3 installer $pythonUrl = "https://www.python.org/ftp/python/3.13.0/python-3.13.0-amd64.exe" $pythonInstaller = "$env:TEMP\python-installer.exe" # Output message: Starting download Write-Output "Downloading Python installer from $pythonUrl..." # Download the Python installer # @DESC: Downloads the Python installer from the specified URL and saves it to the defined path Invoke-WebRequest -Uri $pythonUrl -OutFile $pythonInstaller # Output message: Download complete Write-Output "Download complete. Installing Python..." # Install Python silently and add it to the PATH # @DESC: Executes the installer with silent mode, installs for all users, and adds Python to the system PATH Start-Process -FilePath $pythonInstaller -ArgumentList "/quiet InstallAllUsers=1 PrependPath=1" -Wait # Output message: Installation complete Write-Output "Installation complete. Cleaning up..." # Clean up the installer file # @DESC: Removes the installer file after installation to free up space Remove-Item -Path $pythonInstaller -Force # Output message: Cleanup complete Write-Output "Cleanup complete. Verifying installation..." # Verify the installation # @DESC: Prints the installed Python version to verify successful installation $pythonVersion = python --version Write-Output "Python installation and verification complete." Write-Output "Installed version: $pythonVersion" # Get installation statistics $stats = Get-InstallationStats Write-Output "Installation Date: $($stats.InstallDate)" Write-Output "Operating System Version: $($stats.OSVersion)" }
Paste Settings
Paste Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax Highlighting :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Paste Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create New Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
Deutsch
English
Do you like cookies?
🍪 We use cookies to ensure you get the best experience on our website.
Learn more
I agree