logging line by line results

Author Message
strinh200378

  • Total Posts : 3
  • Scores: 0
  • Reward points : 0
  • Joined: 4/22/2009
  • Status: offline
logging line by line results Wednesday, April 22, 2009 2:08 PM (permalink)
0
I'm used to Korn shell scripts and in korn, you can log within the scripts or the whole script itself.

ie.

#start log file
echo > c:\scripts\logfile.log
echo 'date' >> c:\scripts\logfile.log
copy file1 file2 >> c:\scripts\logfile.log 2>&1
echo "end script" >> c:\scripts\logfile.log

alternatively you can even do

myscript.ksh > c:\scripts\logfile.log

I can't to seem to do this in powershell.  For example, I've created a simple function script that displays the computer name, windows name, service pack level and os version #.

From another script, i wanted to call this function and log the information.

ie.
$objLogFile = New-Item -type file "c:\scripts\logfile.log" -Force
GetComputerInfo | Out-File c:\scripts\logfile.log

The log file is empty.

I've tried
GetComputerInfo > c:\scripts\logfile.log

I get nothing.

I've looked at the start-transcript/end-transcript but that's like writing another script to log a script.

Thanks in advance!

 
#1
    ebgreen

    • Total Posts : 8227
    • Scores: 98
    • Reward points : 0
    • Joined: 7/12/2005
    • Status: offline
    RE: logging line by line results Thursday, April 23, 2009 2:01 AM (permalink)
    0
    Well, it will really depend on what GetComputerInfo is doing. Post it if you want more specific help. In the meantime, normal stream redirection works fine in PS, so:

    GetComputerInfo > c:\scripts\logfile.log
    "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
    Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
    http://www.visualbasicscript.com/m_47117/tm.htm
     
    #2
      strinh200378

      • Total Posts : 3
      • Scores: 0
      • Reward points : 0
      • Joined: 4/22/2009
      • Status: offline
      RE: logging line by line results Thursday, April 23, 2009 4:57 AM (permalink)
      0
      function GetComputerInfo {
      $strComputerName = Get-Content env:computername
      $objOperatingSystem = Get-WmiObject -Class win32_OperatingSystem -Namespace "root\CIMV2" -ComputerName $strComputerName

      write-host $objOperatingSystem.__SERVER
      write-host $objOperatingSystem.Caption
      write-host $objOperatingSystem.Version
      write-host $objOperatingSystem.CSDVersion

      Here is GetComputerInfo
       
      #3
        ebgreen

        • Total Posts : 8227
        • Scores: 98
        • Reward points : 0
        • Joined: 7/12/2005
        • Status: offline
        RE: logging line by line results Thursday, April 23, 2009 5:35 AM (permalink)
        0
        Change Write-Host to Write-Output so the output goes to STDOUT.
        "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
        Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
        http://www.visualbasicscript.com/m_47117/tm.htm
         
        #4
          strinh200378

          • Total Posts : 3
          • Scores: 0
          • Reward points : 0
          • Joined: 4/22/2009
          • Status: offline
          RE: logging line by line results Thursday, April 23, 2009 7:04 AM (permalink)
          0
          Hey that seems to have work! :)

          Thanks much!
           
          #5

            Online Bookmarks Sharing: Share/Bookmark

            Jump to:

            Current active users

            There are 0 members and 1 guests.

            Icon Legend and Permission

            • New Messages
            • No New Messages
            • Hot Topic w/ New Messages
            • Hot Topic w/o New Messages
            • Locked w/ New Messages
            • Locked w/o New Messages
            • Read Message
            • Post New Thread
            • Reply to message
            • Post New Poll
            • Submit Vote
            • Post reward post
            • Delete my own posts
            • Delete my own threads
            • Rate post

            2000-2012 ASPPlayground.NET Forum Version 3.9