PowerShell: Run Exe from Web

Oct 1, 2021

So there are times that you may need to run an executable (exe) across many devices, and maybe those devices are across several organizations or not on a Windows Domain. With this script you can upload the file to a central web server and the script will download the file and run it on devices.

Note: This script was created for our previous Remote Monitoring and Management system (RMM) though could be modified to be ran in an organization on remote machines using PSRemoting.

    [string]$packageUri, # url to downlaod the exe from
    [string]$packageName, # what to name the exe
    [string]$packageSwitches #any package switches
) #end param

$path = "C:\"
$folder = "Tools"
$fullPath = -join($path,$folder,"\",$packageName)

function Test-Folder {
    if (-Not (Test-Path -Path $folder)) {
        New-Item -Path $path -Name $folder -ItemType "directory" -Force
} #end Test-Folder

function Get-Installer {
    if (Test-Path -Path $fullPath) {
        Remove-Item -Path $fullPath -Force
    Invoke-WebRequest -Uri $packageUri -OutFile $fullPath
} #end Get-Installer

Test-Folder #verify the folder exists
Get-Installer #download a new installer
#run the install
Start-Process $fullPath -ArgumentList $packageSwitches -NoNewWindow -Wait

exit 1

It’s a pretty simple script. Not flashy but it works.

If you want more or need help, stop over at our forums.



Father, Veteran, HomeLab User, Tech Enthusiast, Open Source Advocate, Network Engineer, Content Creator, Developer. Thoughts are my own.


Submit a Comment