Logging in PowerShell script like as MSBuild format

This topic contains 3 replies, has 2 voices, and was last updated by  Vern Anderson 3 years, 4 months ago.

  • Author
    Posts
  • #14258

    Ren Jith
    Participant

    Hi All,

    I am new here, My questions is

    How can I do logging in my PowerShell script which will look like a MSBuild logging.

    MSBuild error message are like,

    C:\dir1\foo.resx(2) : error BC30188: Declaration expected.

    I want this type of logging in my PowerShell script. I don't want to call an MSBuild project from PowerShell for this.

    Is there any way to do this?

    Thanks,

  • #14259

    Vern Anderson
    Participant

    Each CMDLET has the common variables which contain. . .

    -Verbose
    -Debug
    -WarningAction
    -WarningVariable
    -ErrorAction
    -ErrorVariable
    -OutVariable
    -OutBuffer

    You can specify Out Variable and then output the output of each command to a log file. This is how I like to do it. There may be better ways. Let me make a simple example.

    Get-Service v* -OutVariable VService ## Note that my variable name "VService" does NOT have the dollar sign
    $VService ## Now contains all your output
    ## At the end of your script you can simply use Out-File to send the content of each of your variables to a log file
    $VService | Out-File -FilePath .\vservice.log -Append

    you can do the same kind of thing with more than just output you can capture the warnings and errors with -WarningVariable and -ErrorVariable and maybe write those to a separate log.

    -VERN

  • #14260

    Ren Jith
    Participant

    But I need the script output in MSBuild output format

  • #14265

    Vern Anderson
    Participant

    Ah I am not a developer so I have no idea what you are saying when you say MSBuild.

    It looks a lot like XML so you may be able to play with the ConvertTo-Xml or Export-Clixml CMDLETs to make it work. Otherwise you would have to write your own format function to format table output into this XML Like "MSBuild" format. Sorry I missed that point.

    This may also help http://stackoverflow.com/questions/869278/how-to-invoke-msbuild-from-powershell-using-operator or http://www.verious.com/article/invoke-ms-build-powershell-module/

    -VERN

You must be logged in to reply to this topic.