header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Trying to convert vb to powershell
Last Post 23 Jul 2010 08:55 AM by Ryan. 3 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
RyanUser is Offline
New Member
New Member
Posts:16
Avatar

--
23 Jul 2010 06:11 AM
    I have a vb function that is used to timestamp lines on log files that the bigger vbscript creates.

    I am trying to convert this functionality to powershell as well.

    Was hoping I could get some help sorting it out.

    Here is the vb:
    Function WTL(LineToProcess) Dim objFSO ' Private Variable Set objFSO = CreateObject("scripting.filesystemobject") If not objFSO.FileExists(LogFileName) Then Else LogFile.Writeline (Now) & " --- " & LineToProcess End If WScript.Echo(Now) & " --- " & LineToProcess End Function

    Any help would be appreciated.

    Thanks,
    Ryan
    PoSherLifeUser is Offline
    Basic Member
    Basic Member
    Posts:364
    Avatar

    --
    23 Jul 2010 06:42 AM
    Try this:

    function WTL ($LineToProcess,$LogFileName) {
        if (Test-Path $LogFileName) { "$(Get-Date) --- $($LineToProcess)" | Add-Content $LogFileName }
        "$(Get-Date) --- $($LineToProcess)"
    }
    When at first you don't succeed Step-Into

    http://theposherlife.blogspot.com
    http://www.jandctravels.com

    George HowarthUser is Offline
    Basic Member
    Basic Member
    Posts:360
    Avatar

    --
    23 Jul 2010 06:55 AM
    VB: WScript.Echo(Now) & " --- " & LineToProcess
    PowerShell: [System.Windows.Forms.MessageBox]::Show(("{0} --- {1}" -f (Get-Date), $LineToProcess))
    RyanUser is Offline
    New Member
    New Member
    Posts:16
    Avatar

    --
    23 Jul 2010 08:55 AM
    That does give me what I'm looking for, but so far only seems to work if my first input into the function is a string.

    Ultimately I am trying to capture the output of some processes I kick off, but instead of sending the output to the console, I want to send it to a file, and have each line of that output timestamped.

    Basically I'm trying to create a log of a script I've written that kicks off multiple exe's.  I control what is sent to the console, but in the event that something doesn't work as expected, I am also creating a more verbose log file that also shows when certain processes are kicked off.

    Right now it seems if I try to put a [System.Diagnostics.Process]::start($process) as the first argument after calling the WTL function, it never starts the process (but oddly the script doesn't error out either).

    Is there a way to accomplish this?

    Thanks for all of the help thus far.
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer