12 Replies Latest reply on Oct 25, 2018 5:47 AM by ben_turner_

    Working with PowerShell Transcript Log Files

    vMarkusK1985 Hot Shot
    vExpert

      Hallo,

       

      has anyone tried to properly collect PowerShell Transcript Log Files?

      Default is that each Line is a New Event, that does no work properly in case of errors and multi Line Messages. I also tried with my own Event marker, but that is not really flexible.

       

      Normal Log:

      **********************
      Windows PowerShell transcript start
      Start time: 20170531171206
      Username: 
      RunAs User: 
      Machine: 
      Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell_ise.exe
      Process ID: 7024
      **********************
      Transcript started, output file is D:\Dev\VmConfigTrigger\Output-05312017-051206.txt
      vmConfigTrigger log Number 05312017-051206 Starts
      '2' VMs were found in Config File to Process.
      
      
      Name                                                 RAM CPU
      ----                                                 --- ---
      test                                                     1
      aijuPrpMNIOhRotQzSmDUqHBJAkTwGYVKCdxWFfcXegvZEbysnlL 1   1
      
      
      
      
      '1' VMs found with matching Name Pattern 'test'
      WARNING: Name 'test' Not Unique Identified in VM 'TESTSCCMDMH2'!
      '1' VMs found with matching Name Pattern 'aijuPrpMNIOhRotQzSmDUqHBJAkTwGYVKCdxWFfcXegvZEbysnlL'
        VM 'aijuPrpMNIOhRotQzSmDUqHBJAkTwGYVKCdxWFfcXegvZEbysnlL' Unique Identified!
        VM 'aijuPrpMNIOhRotQzSmDUqHBJAkTwGYVKCdxWFfcXegvZEbysnlL': Needs RAM Change. '1' GB RAM.
        VM 'aijuPrpMNIOhRotQzSmDUqHBJAkTwGYVKCdxWFfcXegvZEbysnlL': Needs CPU Change. '1' vCPU.
        VM 'aijuPrpMNIOhRotQzSmDUqHBJAkTwGYVKCdxWFfcXegvZEbysnlL': Actual vCPU´s. '1'.
        VM 'aijuPrpMNIOhRotQzSmDUqHBJAkTwGYVKCdxWFfcXegvZEbysnlL': New vCPU´s. '1'.
        VM 'aijuPrpMNIOhRotQzSmDUqHBJAkTwGYVKCdxWFfcXegvZEbysnlL': vCPU´s already fine.
      **********************
      Windows PowerShell transcript end
      End time: 20170531171207
      **********************
      
      
      
      
      
      
      

       

      Log With an Error:

      **********************
      Windows PowerShell transcript start
      Start time: 20170531171747
      Username: 
      RunAs User: 
      Machine: 
      Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell_ise.exe
      Process ID: 7024
      **********************
      Transcript started, output file is D:\Dev\VmConfigTrigger\Output-05312017-051747.txt
      vmConfigTrigger log Number 05312017-051747 Starts
      
      
      PS>TerminatingError(ConvertFrom-Json): "Invalid JSON primitive: 
          {
              "Name": "aijuPrpMNIOhRotQzSmDUqHBJAkTwGYVKCdxWFfcXegvZEbysnlL",
              "RAM": "1",
              "CPU": "1"
          }
      ]
      ."
      ConvertFrom-Json : Invalid JSON primitive:
          {
              "Name": "aijuPrpMNIOhRotQzSmDUqHBJAkTwGYVKCdxWFfcXegvZEbysnlL",
              "RAM": "1",
              "CPU": "1"
          }
      ]
      .
      At D:\Dev\VmConfigTrigger\VmConfigTrigger.ps1:35 char:77
      +     [Array] $Configs = Get-Content -Raw -Path "$PSScriptRoot\Config.json" | Conv ...
      +                                                                             ~~~~
          + CategoryInfo          : NotSpecified: (:) [ConvertFrom-Json], ArgumentException
          + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertFromJsonCommand
      
      
      D:\Dev\VmConfigTrigger\VmConfigTrigger.ps1 : Failed to Read Config File!
          + CategoryInfo          : InvalidData: (:) [Write-Error], WriteErrorException
          + FullyQualifiedErrorId : FailedReadConfigFile,VmConfigTrigger.ps1
      
      
      D:\Dev\VmConfigTrigger\VmConfigTrigger.ps1 : A Global Error occured, Script will stop! Problem needs to be resolved and then the Script can be restarted,
          + CategoryInfo          : OperationStopped: (:) [Write-Error], WriteErrorException
          + FullyQualifiedErrorId : GlobalError,VmConfigTrigger.ps1
      
      
      **********************
      Windows PowerShell transcript end
      End time: 20170531171747
      **********************
      
      
      
      
      
      
      
      
      

       

      Maybe a special Parser or some PS Tricks can do that, or Transcript is a Bad Idea at all... Any help is welcome.

       

      Kind Regards,

      Markus