-
Notifications
You must be signed in to change notification settings - Fork 0
/
Workstations - Update Punchh Files.ps1
83 lines (66 loc) · 2.47 KB
/
Workstations - Update Punchh Files.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
$source = "C:\Windows\Temp\punchhinterface.dll"
$destination = "C:\Micros\Simphony\WebServer\wwwroot\EGateway\Handlers\ExtensionApplications\PunchhInterface\punchhinterface.dll"
$xmlFilePath = "C:\Micros\Simphony\WebServer\wwwroot\EGateway\Handlers\ExtensionApplications\PunchhInterface\PunchhConfig.xml"
$txtFilePath = "C:\Micros\Simphony\WebServer\wwwroot\EGateway\Handlers\ExtensionApplications\PunchhInterface\PunchhSettings.txt"
$xmlContent = @"
<?xml version="1.0" encoding="utf-8"?>
<PunchhConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<LogLevel>6</LogLevel>
<PrintBarcodes>1</PrintBarcodes>
<ShortKey>$shortKey</ShortKey>
<Diagnostics>0</Diagnostics>
<Header />
<Trailer1 />
<Trailer2 />
<Trailer3 />
<Trailer4 />
<Trailer5 />
<UpdateInterval>60</UpdateInterval>
</PunchhConfiguration>
"@
$txtContent = @"
PunchhDiscountObjectNumber=9001
PunchhIntendedDiscountObjectNumber=9002
PropertyLocationKey[$propertyCode]=$locationKey
"@
# Stop servicehost.exe
taskkill /f /t /im servicehost.exe
Start-Sleep -Seconds 5
# Remove existing destination file
Remove-Item $destination -Force
# Move source file to destination
if (Test-Path $source) {
Move-Item $source $destination -Force
} else {
Write-Host "Source file not found."
}
# Write XML content to file
$xmlContent | Out-File -FilePath $xmlFilePath -Force
# Write TXT content to file
$txtContent | Out-File -FilePath $txtFilePath -Force
$folderPath = "C:\micros\simphony\webserver\wwwroot\egateway\handlers\ExtensionApplications\punchhinterface"
# Check if folder exists
if (Test-Path -Path $folderPath) {
try {
# Get ACL of the folder
$acl = Get-Acl -Path $folderPath
# Define a new access rule granting full control to all users
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("Users", "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow")
# Add the rule to the ACL
$acl.AddAccessRule($rule)
# Apply the modified ACL to the folder
Set-Acl -Path $folderPath -AclObject $acl
Write-Output "Permissions granted successfully."
} catch {
Write-Error "Error occurred while granting permissions: $_"
}
} else {
Write-Error "Folder not found: $folderPath"
}
if ($reboot -eq "True") {
# Reboot the system
Restart-Computer -Force
} else {
# Run ServiceHost.exe
Start-Process "C:\Micros\Simphony\WebServer\ServiceHost.exe"
}