Z
Z
Zorichok2018-09-14 16:04:48
PowerShell
Zorichok, 2018-09-14 16:04:48

Downloading skype using PowerShell?

Task: make a policy that will install and update Skype for desktop.
I divided the task into 3 conditional subtasks:
1) Installation
2) Downloading new versions.
3) installing updates
1 and 3 the task can be solved using a batch file, here is its code

set VERSION=8.27.0.85
if %PROCESSOR_ARCHITECTURE% == x86 (
  set FILENAME="C:\\Program Files\\Microsoft\\Skype for Desktop\\Skype.exe"
) else (
  set FILENAME="C:\\Program Files (x86)\\Microsoft\\Skype for Desktop\\Skype.exe"
)
wmic datafile where name=%FILENAME% get version | find "%VERSION%"
if ERRORLEVEL 1 \\local.company.com\SHARES\PACKAGES\Skype-%VERSION%.exe /VERYSILENT /NORESTART

reads which version is installed if not one starts a silent installation.
The 2nd subtask is the one with which I need the community's help
. Ideally, get the name of the file available at this link, compare it with the version available and if they differ, download the file from
As not ideal, but working. Download file from Keeping its name .
at the moment gave birth to such a script
$Url = "https://go.skype.com/windows.desktop.download"
$Path = "D:\1.exe" 
$WebClient = New-Object System.Net.WebClient

$WebClient.DownloadFile($url,$path)

actually the question is how to push the name of the file that we are downloading into the $Path variable. Exactly how to get it

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
azarij, 2018-09-14
@Zorichok

so you can see what version is on the server without downloading the file. Well, the name of the file. if microsoft changes it in the current setup, the code below will stop working.
$uri = " https://get.skype.com/go/getskype-skypeforwindows "
$request = Invoke-WebRequest -Uri $uri -method Get -MaximumRedirection 0 -ErrorAction SilentlyContinue
$skype_ver_on_server = ($request.headers.location - replace ".*/skype-|\.exe").Trim()
$skype_ver_on_server

Z
Zorichok, 2018-09-18
@Zorichok

thank you so much for your help!!!
if anyone needs it, I post the final version of the script !!
$PatchScrpts ="D:\SkypeInstal\Final"
# Get the latest version of SKYPE from the server
$uri = " https://get.skype.com/go/getskype-skypeforwindows "
$request = Invoke-WebRequest -Uri $uri -method Get -MaximumRedirection 0 -ErrorAction SilentlyContinue
$skype_ver_on_server = $request.Headers.Location
# Parse get string extract version !!
$skype_ver_on_server =$skype_ver_on_server -replace ".*/Skype-",""
$skype_ver_on_server =$skype_ver_on_server -replace ".exe",""
$skype_ver_on_local = Get-Content $PatchScrpts\localver.txt
# Check local and received versions IF NOT EQUAL download, change version in 2 places....
if ( $skype_ver_on_local -ne $skype_ver_on_server )
{
# Download new
$Url = " https://go.skype.com/windows.desktop.download "
$Path = $PatchScrpts + "\Skype-"+ $skype_ver_on_server + ".exe"
$WebClient = New-Object System.Net.WebClient
$WebClient. DownloadFile($url,$path)
# Change to txt
$skype_ver_on_server | Out-File $PatchScrpts\localver.txt
# Change in batch file
$FileName = $PatchScrpts+"\SkypeInst.Bat"
[String]$string = "set VERSION="+$skype_ver_on_server
Foreach ($Line in $FileOriginal){
if ($Line.StartsWith("set VERSION="))
{
$FileModified += $Line.Replace($Line, $string)
} else {
$FileModified += $Line
}
}
Set-Content $fileName $FileModified -Force
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question