Worklet: Install Evernote on Windows

  • 18 October 2019
  • 0 replies
  • 29 views

Userlevel 7

Installs Evernote on Windows



Evaluation code:



#REQUIRES -Version 2.0

<#

.SYNOPSIS

This Test script checks to see if Evernote is installed

.DESCRIPTION

This script queries the installed files for 32 and 64bit software

and returns a 0 if product is installed or 1 if not

.Notes

File Name :Evernote_Install_Test.ps1

Author :Automox

Prerequisite :PowerShell V2 over win7 and upper

#>

#Handle Exit Codes:

trap { $host.ui.WriteErrorLine($_.Exception); exit 90 }



function Evernote_Install_Test {



<#

.SYNOPSIS

This function Check for the Evernote is available on system or not .

.DESCRIPTION

After checking the evernote availability, based on the exit code tool will decide to call remediation or not.

.EXAMPLE

Evernote_Install_Test

.NOTES

#>



# Application Name which is to be installation verified.

$appName = 'Evernote'

# Finding the Systen Directory (system32 Directory).

$sysDir = [Environment]::SystemDirectory



# Making the 32 bit and 64 bit path names blank.

$32BIT = ""

$64BIT = ""



#Get Registry value for the 32 bit software installed on both 32-bit and 64-bit machine

Try { $32BIT = Get-ItemProperty 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' -ErrorAction Stop |

Select-Object DisplayName |

Select-String "$appName" |

Out-String

}

Catch { $Exception = $error[0].Exception.Message + "`nAt Line " + $error[0].InvocationInfo.ScriptLineNumber;

Write-Output $Exception

exit 90

}

# Script blcok Which will handle the reading registry for the Evernote installer.

# Match name in the block should be hard coded.

$scriptBlock = {$key = Get-ItemProperty 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' |

Where-Object { $_.DisplayName -match 'Evernote'}

return $key }



# Get the Registry value for the 32 bit software installed on the 64 bit machine. as the automox process is 32 bit

if ((Get-WmiObject Win32_OperatingSystem).OSArchitecture -eq "64-bit")

{

# Call for accessing the 64 bit registry incase 32 bit process not access the registry.

Try

{

$installed64 = @(& "$env:SystemRoot\sysnative\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy Bypass -WindowStyle Hidden -NoProfile -NonInteractive -Command $scriptBlock)

$64BIT = $installed64.DisplayName

}

Catch

{

$Exception = $error[0].Exception.Message + "`nAt Line " + $error[0].InvocationInfo.ScriptLineNumber;

Write-Output $Exception

exit 90

}

}



# Check for the Availability of the software and exit with relevent exit code.

if ($32BIT.Trim() -match $appName -or ($64BIT -ne $null -and $64BIT.Trim() -match $appName)) {

#Application Found.

exit 0

} else {

# Application is not installed! Run Remediation Script to install it.

exit 1

}

}



Evernote_Install_Test



Remediation code:



#REQUIRES -Version 2.0

<#

.SYNOPSIS

This script allows an admin to install Evernote

.DESCRIPTION

This script downloads the quiet exe installer into /Temp and runs it.

Once the script has executed it will remove the install files

This is an example script that has been tested to work on Win10 and Win7.

This script may not work on all systems. Modify to fit your needs

.NOTES

File Name :Evernote_Install.ps1

Author :Automox

Prerequisite :PowerShell V2 over win7 and upper

#>

#Handle Exit Codes:

trap { $host.ui.WriteErrorLine($_.Exception); exit 90 }



function Evernote_Install {



<#

.SYNOPSIS

This function allows automox to Install the Evernote on Windows .

.DESCRIPTION

This function download and installs the latest version of Evernote on system.

.EXAMPLE

Evernote_Install

.NOTES

#>



#############Change the settings in this block#######################

$saveFilePath="$PSScriptRoot\Evernote_Install.exe"



$URL="https://evernote.com/download/get.php?file=Win"

#####################################################################



###### Download the .exe installer file for the installation ######

$downloader = (new-object System.Net.WebClient)

Try {

$downloader.DownloadFile("$URL", "$saveFilePath")

Write-Output "Evernote Installer download finished..."

}

Catch { Write-Output "File download failed. Check URL [$URL] and try again."

exit 90

}



###### Installing Evernote if any errors will be added in the amagent logs ######

Try {

$process = Start-Process -FilePath "$saveFilePath" -ArgumentList "/quiet" -Wait -PassThru -ErrorAction Stop;

Write-Output "Evernote Installion Finished..."

}

Catch { $Exception = $error[0].Exception.Message + "`nAt Line " + $error[0].InvocationInfo.ScriptLineNumber

Write-Output $Exception

exit 90

}



# Avoid error while deleting the installer as process of installation is in progress.

# Wait till installer finished its process completed.

do {

if ((Get-Content $saveFilePath)) {

Write-Output "Installer complete...cleaning up installation files"

Remove-Item -force "$saveFilePath" -ErrorAction SilentlyContinue

exit $process.ExitCode

} else {

Write-Output "Waiting for Installer File Unlock"

}

$fileunlocked = 1

} Until ($fileunlocked)

}



Evernote_Install


0 replies

Be the first to reply!

Reply