2017-05-02 16 views
0

以下のスクリプトを実行して結果をテキストファイルに書き込むことで、2つの長いテキストファイルを比較します。期待される標準比較オブジェクト出力の代わりに、私はその一部を取得し、他のものは(最大文字数の制限やテンプレートの書式などにより)トリミングされます。 ファイルに生の出力を書き込む方法や、正しい結果を得るために行の文字数を増やす方法はありますか? 私が比較したファイルは、どのようにしても短縮または再フォーマットできません。おそらく、私はcompare-object関数の代わりに何か他のものを使うことができますか?powershellの比較オブジェクト出力の問題

ありがとうございました!

スクリプト:

function compareConfigs { 

    Try{ 
     $compareOne = Get-Content $azConfig 
     $comparetwo = Get-Content $dummyConfig 
    } 
    Catch{ 
     Write-Host "Path is invalid or the file does not exist. "  
    } 

Write-Host "Beginning comparison" 
$Compare = Compare-Object $compareOne $compareTwo 

$compare | foreach { 
    if ($_.sideindicator -eq '<=') 
     {$_.sideindicator = $azConfig} 

    if ($_.sideindicator -eq '=>') 
     {$_.sideindicator = $dummyConfig} 
    } 

$Compare | 
select @{l='Value';e={$_.InputObject}},@{l='File';e={$_.SideIndicator}} | 
Out-File $compareResult 

Write-Host "Complete!" 
} 

compareConfigs 

出力:

InputObject                                           
-----------                                           
     <add fileName="E:\Logs\LeadManagement\LeadService.log" rollSizeKB="4096" timeStampPattern="yyyy-MM-dd" rollFileExistsBehavior="Increment" rollInterval="Day" formatter="Text... 
     <add template="Timestamp: {timestamp}&#xA;Message: {message}&#xA;Category: {category}&#xA;Priority: {priority}&#xA;EventId: {eventid}&#xA;Severity: {severity}&#xA;Title:{ti... 
     <add fileName="E:\Logs\LeadManagement\LeadService.log" rollSizeKB="4096" timeStampPattern="yyyy-MM-dd" rollFileExistsBehavior="Increment" rollInterval="Day" formatter="Text... 
     <add template="Timestamp: {timestamp}&#xA;Message: {message}&#xA;Category: {category}&#xA;Priority: {priority}&#xA;EventIwefwefd: {eventid}&#xA;Severity: {severity}&#xA;Tit... 

答えて

1

あなたが選択オブジェクトを使用しているので、あなたはあなたのPSCustomObjectのタイプは$の比較をされたことがわかります。代わりに、私はここに、セパレータとして "`トンを" タブを使用しています、ご注意

$Compare | %{($_.InputObject + "`t" + $_.SideIndicator)} | Out-File $compareResult 

... foreachの-オブジェクト(%)を使用します。

あなたはCSVであなたの出力を望んでいた場合、あなたが持っているものを使用してだけではなく、外のファイルのエクスポート、CSVを使用することができます...

$Compare | select @{l='Value';e={$_.InputObject}},@{l='File';e={$_.SideIndicator}} | Export-CSV -Notype compareResult.csv