Optimizing logging dynamically RRS feed

  • Question

  • I am logging changing server names and the output is currently like this:

    User abc123 HomeDirectory is on Server Server1
    abc123's HomeDirectory is \\Server1\abc123
    Changing abc123's HomeDirectory from \\Server1\abc123 to \\Server2\abc123
    Old ProfilePath Server and New ProfilePath Server are blank
    Skipping change . . .

    I think my code for logging is a little too long and would like to condense it somehow, so I've been working on trying to create a template of some type, but haven't been really successfully. So I'm trying to make the words (HomeDirectory and ProfilePath) dynamic too. So If I use the variables OldHomeDirectory it would dynamically change a variable to Homedirectory and the same with ProfilePath.

    I tried turning the array into a string by using Out-String -Stream and messing with the indexes. That got really messy really quick. I'm not sure if this can even be done, but I am trying to see if anyone has any ideas. I also was coming up with the idea if I could take the column names dynamically and do a for loop of some king. I just don't have any more ideas on how to do this. Can anyone help me? Here's my code so far:

    Code deleted

    • Edited by lytvinh Tuesday, December 19, 2017 1:13 PM
    • Moved by Bill_Stewart Friday, January 26, 2018 3:36 PM Unanswerable drive-by question
    Friday, December 15, 2017 8:59 PM

All replies

  • Just use Start-Transcript and skip all of the output to the console.  "Write-Host" cannot be sent to a file.


    Friday, December 15, 2017 9:02 PM