Output Clean Up

This topic contains 0 replies, has 1 voice, and was last updated by Profile photo of Forums Archives Forums Archives 5 years, 4 months ago.

  • Author
    Posts
  • #5050

    by dagr8tim at 2012-08-28 05:48:15

    I created alittle script to compare the web.config files from our production with our non production environmental to identify any non environmental differences. I'm very happy with the script, but the output sucks. I tried adding the format wide option to the output string, but that didn't help. Any suggestions on cleaning up the output?

    # Creates a list of applications from the production web server. Comment out once list is created.
    # gci \\ -recu web.config | select-string "" | foreach{$_.Path} > C:\temp\compare\list.txt

    #Destination/Working Folder
    $Dest_Folder = "C:\temp\compare"
    $date = Get-Date
    #Loads list file for use
    $list = Get-Content -Path "$Dest_Folder\list.txt"
    # Writes date to appended file
    "$date" >"C:\temp\compare\compare.txt"

    foreach ($prodfilename in $list) {

    $stagefilename = $prodfilename.Replace("\\", "\\")
    "`n`nComparing $prodfilename vs $stagefilename" >> "C:\temp\compare\compare.txt"
    $File_Path1 = Get-Content -Path "$prodfilename"
    $File_Path2 = Get-Content -Path "$stagefilename"

    Compare-Object $File_Path1 $File_Path2 -SyncWindow 200 >> "C:\temp\compare\compare.txt"

    }

    by poshoholic at 2012-08-28 05:56:29

    I think it would be helpful if you included a sample showing the output you get from this now, followed by the information you would like to see in the output more clearly so that someone can offer suggestions on how to change the output that is returned from this script.

    by dagr8tim at 2012-08-28 06:30:24

    [quote="poshoholic"]I think it would be helpful if you included a sample showing the output you get from this now, followed by the information you would like to see in the output more clearly so that someone can offer suggestions on how to change the output that is returned from this script.[/quote]

    Here's my output. My two complaints are 1) that it seems to stop the lines at 80 characters, 2) that it doesn't seem to parse the entire file.

    08/28/2012 08:31:39

    Comparing \\\Web.config vs \\\Web.config

    InputObject SideIndicator
    ———– ————-

    < !–


    http://odhappclstg1... =>
    < !–

    http://odhappclprd1... =>

    < !–
    < !– < !– http://odhappclstg1... < =
    http://odhappclprd1... < =
    < !–

    by DonJ at 2012-08-28 06:33:23

    So, the line stopping is expected. Pipe the output to Format-Table -wrap to fix that, or widen your PowerShell window.

    by poshoholic at 2012-08-28 06:37:52

    Right, now I get you. You can work around the PowerShell window width limitations that you're seeing and get the output without these limitations in a text file using some techniques that have already been blogged about before.

    As for whether or not it properly compares the entire file, you should be able to raise your -SyncWindow value to something much larger so that it can compare larger files.

    by dagr8tim at 2012-08-28 09:21:49

    Thank you for all of your help. That should be enough to get me moving forward on this.

    EDIT:
    This is what I came up with that works for me. This is the last two lines of the script.
    $a = @{Expression={$_.InputObject};Label="Web Config Line";width=140},@{Expression={$_.SideIndicator};Label="Side Indicator";width=15}
    Compare-Object $File_Path1 $File_Path2 | Format-Table -Property $a -wrap | Out-String -Width 4096 | Out-File C:\temp\compare\compare.txt

    This solves the output problem. Now I just need to suppress entries that exist in production but not in non production so I don't get errors in my report.

    by poshoholic at 2012-08-28 18:17:27

    Excellent, glad it worked out for you! Do you mind if I mark this topic as solved then?

    by dagr8tim at 2012-08-29 06:39:13

    [quote="poshoholic"]Excellent, glad it worked out for you! Do you mind if I mark this topic as solved then?[/quote]

    Absolutely. I've made some tweaks to the script, so I'll post the entire script in it's current form in case somebody is trying to do something similar.

    #Destination/Working Folder
    $Dest_Folder = "C:\temp\compare"

    # Creates a list of applications from the production web server. Comment out once list is created.
    # gci \\ -recu web.config | select-string "" | foreach{$_.Path} > "$Dest_Folder\list.txt"

    $date = Get-Date
    #Loads list file for use
    $list = Get-Content -Path "$Dest_Folder\list.txt"
    # Writes date to appended file
    "$date" >> "$Dest_Folder\compare.txt"

    foreach ($prodfilename in $list) {
    $stagefilename = $prodfilename.Replace("\\", "\\")
    "`n`nComparing $prodfilename vs $stagefilename" >> "$Dest_Folder\compare.txt"
    $File_Path1 = Get-Content -Path "$prodfilename"
    $File_Path2 = Get-Content -Path "$stagefilename"
    if(!(test-path -path $stagefilename)) {
    "`nStage File Not Found: $stagefilename" >> "$Dest_Folder\compare.txt"
    continue
    }
    $a = @{Expression={$_.InputObject};Label="Web Config Line";width=140},@{Expression={$_.SideIndicator};Label="Side Indicator";width=15}
    Compare-Object $File_Path1 $File_Path2 | Format-Table -Property $a -wrap | Out-String -Width 6144 >> "$Dest_Folder\compare.txt"
    }

    by poshoholic at 2012-08-29 06:51:49

    Thanks for sharing your final script!

You must be logged in to reply to this topic.