Not able to put my Switch output to a logfile

This topic contains 5 replies, has 3 voices, and was last updated by  situscript 7 months ago.

  • Author
  • #84479


    Hi Guys,

    Here is the piece of code where i am picking an IP and connecting to it and then running a command to show all the port errors and then trying to put that output into a text file. At last sending that output to my mail.

    So everything is working out as perfect as i want but i am getting a mail with an empty attachment, where i don't see my port errors and rather the date and the IP . could anybody please help me in solving the issue. i am sure that i am missing a small one.

    $SMTPSRV = ""
    $EmailFrom = ""
    $EmailTo =""
    $logFile = "Brocade-Log-" + (Get-date -f dd ).tostring() + (Get-date -f MM ).tostring() + ((Get-Date).year).tostring() + ".txt"

    (get-date) > $logFile

    Get-Content C:\Users\xyzpa\Desktop\fibre-switches.txt | % { $_ >> $logFile ; & 'C:\Users\xyzpa\Desktop\putty.exe' -l admin -pw Sty34viR -m C:\Users\xyzpa\Desktop\brocade1.txt $_ >> $logFile}
    #Get-Content .\Desktop\fibre-switches.txt | % { & '.\Desktop\putty.exe' -l admin -pw password -m .\brocade2.txt $_ }

    $MyReport = "Cleared Fibre switch errors for all brocade switches"
    Send-MailMessage -To $EmailTo -Subject "Brocade switch error clear." -From $EmailFrom -Body $MyReport -SmtpServer $SMTPSRV -Attachments $LogFile

    output of the above script.

    Friday, November 17, 2017 6:53:26 PM

    Here is the files used in the script.

    fibre-switches.txt :
    brocade1.txt : porterrshow

  • #84482

    Pradeep Arora

    I would put full path into the $logfile, that way I know where it is being created and then go check it. Otherwise you might be trying to create it in Windows\System

    • #84493


      I Tried with full path but not working. Same output is coming. and what will i create in windows/system

    • #84494


      I tried with only the below but still is not coming anything in the output.

      $logFile = 'C:\Users\khvs087pa\Desktop\porterrshow.txt'

      (get-date) >> $logFile

      Get-Content C:\Users\khvs087pa\Desktop\fibre-switches.txt | % { $_ >> $logFile ; & 'C:\Users\khvs087pa\Desktop\putty.exe' -l admin -pw xyz -m C:\Users\khvs087pa\Desktop\brocade1.txt $_ >> $logFile}

      and the output is same:

      Friday, November 17, 2017 7:29:20 PM

  • #84499

    iain Barnetson

    Not what you're looking for but couldn't help notice how you name your file, with the date

    $logFile = "Brocade-Log-" + (Get-date -f dd ).tostring() + (Get-date -f MM ).tostring() + ((Get-Date).year).tostring() + ".txt"

    ....and wanted to suggest

    $logfile = "Brocade-Log-$((GET-DATE).ToString("ddMMyyyy")).txt"

    which will return: "Brocade-Log-17112017.txt"

    • #84505


      thanks for the suggestion @iain

You must be logged in to reply to this topic.