-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSampleScript.ps1
59 lines (53 loc) · 1.82 KB
/
SampleScript.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# This is a sample script to test the Latest Version Check
[CmdletBinding()]
param (
[Parameter(Mandatory=$false)]
[Switch]
$SkipVersionCheck
)
# Get the full script path
$ScriptFullPath = $MyInvocation.MyCommand.Path
# Get Script Location
$ScriptLocation = Split-Path -Parent $ScriptFullPath
# Set the Script version
$ScriptVersion = "1.0"
Write-Host "Starting the script"
Import-Module .\LatestVersionCheck\LatestVersionCheck.psd1
$gitHubLatestVersionParameters = @{
currentVersion = $ScriptVersion;
repositoryName = "AssafMiron/CheckLatestVersion";
scriptVersionFileName = "SampleScript.ps1";
sourceFolderPath = $ScriptLocation;
# More parameters that can be used
# repositoryFolderPath = "FolderName";
# branch = "main";
# versionPattern = "ScriptVersion";
}
If(! $SkipVersionCheck)
{
try{
# For the sample we will send a lower script version
$gitHubLatestVersionParameters.currentVersion = "0.5";
Write-Host "Current script version $($gitHubLatestVersionParameters.currentVersion)"
$isLatestVersion = $(Test-GitHubLatestVersion @gitHubLatestVersionParameters)
If($isLatestVersion -eq $false)
{
# Skip the version check so we don't get into a loop
$scriptPathAndArgs = "& `"$ScriptFullPath`" -SkipVersionCheck"
Write-Host "Finished Updating, relaunching the script"
# Run the updated script
Invoke-Expression $scriptPathAndArgs
# Exit the current script
return
}
} catch {
Write-Error "Error checking for latest version." -Exception $_.Exception
}
}
Write-Host "This is the current script version $ScriptVersion, checking script version from GitHub"
If($(Test-GitHubLatestVersion @gitHubLatestVersionParameters -TestOnly))
{
Write-Host "This is the latest script version"
}
Remove-Module LatestVersionCheck
Write-Host "Script ended"