FeaturedPower ShellScripts

Download/Install App – PowerShell

Install Application using Powershell

The easiest way to download and install any application from internet is using this script which i created.

1- Create a folder in drive C:

New-Item -ItemType Directory -Path 'C:\files' -Force
$folder = "c:\files"

2- Create variable and paste yoru app url

$url= "https://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU_4/vcredist_x64.exe"

3- use these custom object methods to grab the file and join folder

$req = [System.Net.HttpWebRequest]::Create($url)
$req.Method = "HEAD"
$response = $req.GetResponse()
$fUri = $response.ResponseUri

4- create variable “$filename” to grab the app file name from location saved

$filename = [System.IO.Path]::GetFileName($fUri.LocalPath); 
$response.Close()

5- create a variable “$Target” to store file location and name

$target = join-path $folder $filename

6- Trigger the invoke command to connect to the link and grab the file

Invoke-WebRequest -Uri $url -OutFile $target

7- Lastly run the process command to install the application using the switches

(Start-Process -FilePath $target -ArgumentList "/install /quiet /norestart" -Wait -PassThru).ExitCode

and here is the full script:

#installing VC ++
New-Item -ItemType Directory -Path 'C:\files' -Force
$folder = "c:\files"
$url= "https://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU_4/vcredist_x64.exe"
$req = [System.Net.HttpWebRequest]::Create($url)
$req.Method = "HEAD"
$response = $req.GetResponse()
$fUri = $response.ResponseUri
$filename = [System.IO.Path]::GetFileName($fUri.LocalPath); 
$response.Close()
$target = join-path $folder $filename 
Invoke-WebRequest -Uri $url -OutFile $target 



(Start-Process -FilePath $target -ArgumentList "/install /quiet /norestart" -Wait -PassThru).ExitCode

 

Show More
Back to top button