Mirth 属性 文件在使用 powershell 编辑时损坏

Mirth Property File Corrupted on Editing using powershell

我正在尝试编辑 Mirth 属性 文件以使用 powershell 添加 Microsoft sql 服务器驱动程序 url 和 class 名称。我能够编辑和保存。当我在编辑后启动 Mirth 服务时,Mirth 属性 文件已损坏。但是我查看了原始内容和编辑后的内容。除了添加的更改和文件大小从 5kb 增加到 10kb 之外,一切都一样。谁能帮我吗?这是 powershell 脚本。

$server="Localhost"
$PropertyfilePath = "C:\Program Files\Mirth Connect\conf\mirth.properties"
$connectionString = "jdbc:sqlserver://$($server):1433;instanceName=$($server);databaseName=Mydb;integratedSecurity=true" 
$driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
$data= @()
Copy-Item $PropertyfilePath "D:\Mirthbackup" -force
$newstreamreader = New-Object System.IO.StreamReader($PropertyfilePath)
[int]$eachlinenumber = 1
while (($readeachline = $newstreamreader.ReadLine()) -ne $null)
{
    if($readeachline.Contains("= derby")){
            
        $readeachline.Remove(0)
        $update= "database = sqlserver"
        $data +=$update
        $eachlinenumber++
    }
   elseif($readeachline.Contains("database.url"))
    {
       
        $update=$readeachline.Substring(0,12)+" = "+$connectionString
        $data +=$update
        $eachlinenumber++
        
    }
    elseif($readeachline.Contains(".driver"))
   {
        $readeachline.Remove(0)
        $update ="database.driver = "+$driverName
        $data +=$update
        $eachlinenumber++
    
    }
    else{

        $data +=$readeachline
        $eachlinenumber++
     }
}
$newstreamreader.Dispose()
 
$data | Out-File -FilePath $PropertyfilePath 

您的属性文件应该是 ISO-8859-1 (latin1) 编码的。

尝试将您的代码更改为:

$server="Localhost"
$PropertyfilePath = "C:\Program Files\Mirth Connect\conf\mirth.properties"
$connectionString = "jdbc:sqlserver://$($server):1433;instanceName=$($server);databaseName=Mydb;integratedSecurity=true" 
$driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
$data= @()
Copy-Item $PropertyfilePath "D:\Mirthbackup" -force
$encoding = [System.Text.Encoding]::GetEncoding('iso-8859-1'))
$newstreamreader = New-Object System.IO.StreamReader($PropertyfilePath, $encoding)
[int]$eachlinenumber = 1
while (($readeachline = $newstreamreader.ReadLine()) -ne $null)
{
  # if statements left out
}
$newstreamreader.Dispose()

[System.IO.File]::WriteAllLines($PropertyfilePath,$data, $encoding)