【问题标题】:Mirth Property File Corrupted on Editing using powershell使用 powershell 编辑时 Mirth 属性文件损坏
【发布时间】:2020-09-28 12:28:55
【问题描述】:

我正在尝试编辑 Mirth 属性文件以使用 powershell 添加 microsoft sql server 驱动程序 url 和类名。我能够编辑和保存 .当我在编辑后启动 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 

【问题讨论】:

  • 双倍大小表明您已将编码更改为双字节,可能是 unicode。找出原始文件的编码是什么,并让脚本保留它。
  • 根据question,java 属性文件是 ISO-8859-1 编码的。
  • @PalleDue 非常感谢您的回答。但是内容全部写入一行。当我用 WriteAllLines 替换 WriteAllText 方法时,它更准确。

标签: powershell properties mirth


【解决方案1】:

您的属性文件应采用 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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-12
    • 2022-01-26
    • 1970-01-01
    • 2015-07-25
    • 2017-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多