I wanted a way to keep microSIP updated to the latest version automatically.
I wrote this script and have a couple of questions.
# Create a WebClient object
$webClient = New-Object System.Net.WebClient
# URL for the MicroSIP download page
$url = "https://microsip.org/downloads"
# Download the HTML content of the MicroSIP download page
$html = $webClient.DownloadString($url)
#write-output $html
# Use regular expression to extract the download link for the most recent version of MicroSIP Zip
$newversion = Select-String "(MicroSIP-.......zip)" -InputObject $html
# create full download url
$downloadurl = "https://microsip.org/download/" + $newversion.matches.value
#Write-Output $downloadurl
# check if destination folder exists
$folderPath = $env:HOMEDRIVE + $env:HOMEPATH + "\appdata\local\temp\microsip"
if (!(Test-Path -Path $folderPath -PathType Container))
{
New-Item -ItemType Directory -Path $folderPath
}
# set download destination path and name
$dest = $env:HOMEDRIVE + $env:HOMEPATH + "\appdata\local\temp\microsip\microsip.zip"
#Write-Output $dest
# download file from URL
Invoke-WebRequest -Uri $downloadurl -OutFile $dest
# set user's microsip path
$destuserfolder = $env:HOMEDRIVE + $env:HOMEPATH + "\appdata\MicroSIP"
# extract zip to current user's microsip file
Expand-Archive -LiteralPath $dest -DestinationPath $destuserfolder -Force
# set user's microsip contact path and name
$contact = $env:HOMEDRIVE + $env:HOMEPATH + "\appdata\MicroSIP\Contacts.xml"
# set user's document directory path
$mydocuments = [environment]::getfolderpath("mydocuments")
# backup contacts to user's documents
Copy-Item -Path $contact -Destination $mydocuments -Force
This does the job I want just fine - finds the first entry of MicroSIP.........zip then downloads it, extracts it to the user's microsip folder, then backs up their contacts to their documents folder.
The problems I forsee:
-
If microsip changes their page layout, it's possible the link won't be the first zip on the page
-
If microsip changes the length of their version numbers, the script will break
Any thoughts on how I can fix these?