-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppdataEditFiles.ps1
More file actions
24 lines (24 loc) · 1.24 KB
/
AppdataEditFiles.ps1
File metadata and controls
24 lines (24 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$ParentPath = $env:LOCALAPPDATA
$foldername = "testiappi"
$configfiletoedit = "settings_.dat"
$KillProcess = "notepad.exe"
$FullSearchPath = $ParentPath+"\"+$foldername
$FullSearchPathExists = Test-Path -Path $FullSearchPath
if ($FullSearchPathExists -ne $true) {
exit 1
}
If (((Get-Process).ProcessName -contains $KillProcess)) {
Stop-Process -Name $KillProcess -Force -Confirm:$false
}
$FilesToBeEdited = Get-ChildItem -Path $FullSearchPath -Recurse -Filter $configfiletoedit
$FilesToBeEdited.FullName
ForEach ($FileToEdit in $FilesToBeEdited) {
$FileContent = Get-Content -Path $FileToEdit.FullName
$FileBackup = $FileToEdit.FullName+".old"
Move-Item -Path $FileToEdit.FullName -Destination $FileBackup
$FileContent = $FileContent.Replace("ServerAddress=server1.jotain.com","ServerAddress=serverUUSI1.jotain.com")
$FileContent = $FileContent.Replace("ServerAddress=server2.jotain.com","ServerAddress=serverUUSI2.jotain.com")
$FileContent = $FileContent.Replace("ServerAddress=server3.jotain.com","ServerAddress=serverUUSI3.jotain.com")
$FileContent = $FileContent.Replace("ServerAddress=server4.jotain.com","ServerAddress=serverUUSI4.jotain.com")
Out-File -FilePath $FileToEdit.FullName -Encoding utf8 -InputObject $FileContent
}