
$serviceName = "PCS.HardwareLink"
$folderPath = "$env:ProgramFiles\Party Center Software\Hardware Link\"

# -> Removes Previous Instalation (if exists)
$serviceStatus = Get-Service "$serviceName" -ErrorAction Ignore
if ($null -ne $serviceStatus) {
    sc.exe stop $serviceName
    sc.exe delete $serviceName
}
New-Item -ItemType Directory -Force -Path "$folderPath\files\"
Remove-Item "$folderPath\files\*" -Exclude appsettings.json,appsettings.Hardware.json,.terminalconfig -Recurse -Force -ErrorAction Ignore

# -> Copies new files
Copy-Item $PSScriptRoot\* "$folderPath\files\" -Recurse -Force
Copy-Item $PSScriptRoot\..\uninstall.bat "$folderPath" -Recurse -Force

# -> Create service
$servicePath = (Get-ChildItem $folderPath\files\Pcs.HardwareLink.exe).FullName
New-Service -Name $serviceName -BinaryPathName $servicePath -Description "PCS Hardware Link application" -StartupType Automatic
Start-Service -Name $serviceName
Get-Service -Name $serviceName