NOTE:
Powershell Script - Windows
To run on a local machine without RMM, you may have to bypass the machine’s execution policy with:
powershell.exe -noprofile -executionpolicy bypass -file '.\Timus Silent Install.ps1'
Windows:
<#
Timus Connect Windows Installation Script
***Always review to make sure you know what a script is doing.***
* DISCLAIMER OF WARRANTIES:
*
* THE SOFTWARE PROVIDED HEREUNDER IS PROVIDED ON AN "AS IS" BASIS, WITHOUT
* ANY WARRANTIES OR REPRESENTATIONS EXPRESS, IMPLIED OR STATUTORY; INCLUDING,
* WITHOUT LIMITATION, WARRANTIES OF QUALITY, PERFORMANCE, NONINFRINGEMENT,
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. NOR ARE THERE ANY
* WARRANTIES CREATED BY A COURSE OR DEALING, COURSE OF PERFORMANCE OR TRADE
* USAGE. FURTHERMORE, THERE ARE NO WARRANTIES THAT THE SOFTWARE WILL MEET
* YOUR NEEDS OR BE FREE FROM ERRORS, OR THAT THE OPERATION OF THE SOFTWARE
* WILL BE UNINTERRUPTED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#####################################################################################
<#
1. Check to see if the application is already installed
If already installed, exits the script. Otherwise proceeds with section 2.
#>
$appName = 'Timus Connect'
$RegUninstallKey = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
$installedApplication = Get-ItemProperty -Path $RegUninstallKey | Where-Object {$_.DisplayName -like "*$appName*"}
if ($installedApplication) {
Write-Host "Application is already installed, exiting script"
}
else {
Write-Host "Application is not installed."
}
#####################################################################################
<#
2. Check to see if this is a desktop or laptop by looking for a battery
#!#! Delete this whole line if you want to disable this section #!#! #>
$systemType = "Unknown"
$BatteryStatus = (Get-WmiObject -Class Win32_Battery -EA SilentlyContinue).Status
if ($BatteryStatus) {
$systemType = "Laptop"
} else {
$systemType = "Desktop"
}
Write-Output "This device is a" $systemType
#2.1 At this time I am only automating the Timus installation on laptops
if ($systemType -eq "Desktop") {
Write-Output "The device is a desktop, exiting script."
}
else {
Write-Output "This is a laptop, proceeding with download."
}
#>
#####################################################################################
<#
3. Does the download destination exist?
If not, create download directory
Default download directory is "C:\temp\Timus Networks"
#>
$dlFolder = "C:\temp\Timus Networks"
$dlFolderTest = Test-Path -Path $dlFolder
$dlDest = "$dlFolder\Timus-Connect.exe"
$dlUrl = "https://repo.timuscloud.com/connect/Timus-Connect.exe"
$tempFolderExists = Test-Path -Path "C:\Temp"
if ($dlFolderTest -eq $true) {
Write-Output "Download directory exists, continuing with download."
}
else {
Write-Output "Download directory does not exist, creating directory"
New-Item -ItemType Directory -Path $dlFolder -Verbose -ErrorAction Stop
}
#####################################################################################
<#
4. Starting download to destination
Will try three different methods to download the file: Invoke-WebRequest, WebClient, and finally Start-BitsTransfer.
If all three fail, the script will exit with a failure.
#>
try {
Write-Output "Trying to download..."
Invoke-WebRequest -Uri $dlUrl -OutFile $dlDest
Write-Output "Invoke-WebRequest download was successful, moving on to installation..."
}
catch {
Write-Output "Invoke-Webrequest failed, trying webclient download..."
try {
$webClient = New-Object System.Net.WebClient
$webClient.DownloadFile($dlUrl, $dlDest)
Write-Output "WebClient download was successful, moving on to installation"
}
catch {
Write-Output "WebClient download failed, starting BitsTransfer..."
try {
Start-BitsTransfer -Source $dlUrl -Destination $dlDest
Write-Output "Downloaded successfully with BitsTransfer, moving on to installation..."
}
catch {
Write-Host "All methods failed. Unable to download the file. Exiting."
Exit 1
}
}
}
#####################################################################################
<#
5. Starts Installation of the Timus Connect App.
Upon error, the script will exit.
Checks registry for uninstall key for Timus Connect.
#>
Start-Process -Wait -FilePath $dlDest -ArgumentList "/S" -PassThru -ErrorAction Stop
#Check for successful install
$appName = 'Timus Connect'
$RegUninstallKey = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
$installedApplication = Get-ItemProperty -Path $RegUninstallKey | Where-Object {$_.DisplayName -like "*$appName*"}
if ($installedApplication) {
Write-Host "Application is installed."
} else {
Write-Host "Application is not installed."
}
#####################################################################################
<#
6. Performs cleanup of created files/folders
If download root existed prior to script, will only remove newly created folder.
For example, if C:\temp already existed, the script will only remove C:\temp\Timus Networks
and not C:\temp as a whole.
If download root did not exist, it will delete the whole folder
#>
if ($tempFolderExists -eq $true) {
Write-Output "Temp folder existed prior to download, only removing" $dlFolder
Remove-Item -Path $dlFolder -Recurse -Force
Write-Output "Cleanup complete, exiting..."
Exit 0
}
else {
Write-Output "Temp folder did not exist prior to script, deleting Temp folder..."
Remove-Item -Path "C:\Temp" -Recurse -Force
Write-Output "Cleanup complete, exiting..."
Exit 0
}
0 comments
Please sign in to leave a comment.