Last active
December 6, 2019 15:42
-
-
Save ljtill/eef5fb8f39d1f9f74f575e8d61f0e7be to your computer and use it in GitHub Desktop.
Provides the ability to install & reset the ScaleFT agent state
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[Parameter(Mandatory = $false)] | |
[string]$ApplicationDirectory = "C:\windows\system32\config\systemprofile\AppData\Local\ScaleFT\", | |
[Parameter(Mandatory = $false)] | |
[string]$ApplicationFilename = "ScaleFT-Server-Tools-latest.msi", | |
[Parameter(Mandatory = $false)] | |
[string]$ApplicationUri = "https://dist.scaleft.com/server-tools/windows/latest/ScaleFT-Server-Tools-latest.msi", | |
[Parameter(Mandatory = $false)] | |
[string]$DeviceTokenPath = "state\", | |
[Parameter(Mandatory = $false)] | |
[string]$DeviceTokenFilename = "device.token", | |
[Parameter(Mandatory = $true)] | |
[string]$EnrollmentToken, | |
[Parameter(Mandatory = $false)] | |
[string]$EnrollmentTokenFilename = "enrollment.token", | |
[Parameter(Mandatory = $false)] | |
[string]$ServiceName = "scaleft-server-tools" | |
) | |
begin { | |
Write-Output "Status: Retrieving Windows Service status" | |
$service = Get-Service | Where-Object -FilterScript {$_.Name -eq $serviceName} | |
Write-Output "Status: Setting the script execution mode" | |
$mode = $null | |
if ($null -ne $service) { | |
$mode = "Reset" | |
} else { | |
$mode = "Install" | |
} | |
Write-Output "Status: Validating the Operating System" | |
$operatingSystem = (Get-WmiObject -Class Win32_OperatingSystem).Caption | |
if ($operatingSystem -notlike "*Windows Server*") { | |
Write-Output -Message "Error: Unsupported Operating System" -ErrorAction Stop | |
Exit | |
} | |
} | |
process { | |
switch ($mode) { | |
"Reset" { | |
if ($service.Status -eq "Running") { | |
Write-Output "Status: Stopping ScaleFT Windows Service" | |
Stop-Service -Name $service.Name | |
} | |
$path = Test-Path -Path ($applicationDirectory + $deviceTokenPath + $deviceTokenFilename) | |
if ($path -eq $true) { | |
Write-Output "Status: Removing ScaleFT Device Token" | |
Remove-Item -Path ($applicationDirectory + $deviceTokenPath + $deviceTokenFilename) | |
} | |
$path = Test-Path -Path ($applicationDirectory + $enrollmentTokenFilename) | |
if ($path -eq $true) { | |
Write-Output "Status: Removing ScaleFT Enrollment Token" | |
Remove-Item -Path ($applicationDirectory + $enrollmentTokenFilename) | |
} | |
Write-Output "Status: Creating ScaleFT Enrollment Token" | |
$enrollmentToken | Out-File -FilePath ($applicationDirectory + $enrollmentTokenFilename) | |
Write-Output "Status: Starting ScaleFT Windows Service" | |
Start-Service -Name $serviceName | |
} | |
"Install" { | |
Write-Output "Status: Creating ScaleFT Directory" | |
New-Item -ItemType Directory -Path $applicationDirectory -Force | Out-Null | |
Write-Output "Status: Creating ScaleFT Enrollment Token" | |
$enrollmentToken | Out-File -FilePath ($applicationDirectory + $enrollmentTokenFilename) | |
Write-Output "Status: Downloading ScaleFT Instalation Files" | |
Invoke-WebRequest -Uri $applicationUri -OutFile ($env:TEMP + "\" + $applicationFilename) | |
Write-Output "Status: Installing ScaleFT" | |
Start-Process msiexec.exe -ArgumentList ("/qn /I " + (($env:TEMP + "\" + $applicationFilename))) -Wait | |
} | |
} | |
} | |
end {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment