Announcement

Collapse
No announcement yet.

How can i pause the script to see error

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How can i pause the script to see error

    Hi Experts
    I am very new to powershell scripting i find one script while google fit for my work ,but how do i pause it to see where is the error .



    #we specify the directory where all files that we want to upload are contained PowerShell Script for copying Log Shipping file to FTP
    #we specify the directory where all files that we want to upload are contained

    cd D:\ReplicationViaFTPServer

    $Dir=”D:\ReplicationViaFTPServer\”
    # we specify the directory where all files will move after upload
    $NewDir=”D:\ReplicationViaFTPServerlOG\”
    #ftp server
    #$ftp = “ftp://xxxx1/dir/”
    $ftp = “ftp://xx.xx.xxx/”
    #$user = “Administrator”
    #$pass = “Admr”
    $user = “Anonymous”
    $pass=
    Try
    {
    $webclient = New-Object System.Net.WebClient
    $webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)
    #list every sql server transaction Log file Start-Sleep -s 30 foreach($item in (dir $Dir “*.trn”))
    {
    #”Uploading $item…”
    $uri = New-Object System.Uri($ftp+$item.Name)
    $webclient.UploadFile($uri, $item.FullName)
    #moving the file in other folder move-item $Dir$item $NewDir
    }

    }
    Catch
    {

    $ErrorMessage = $_.Exception.Message
    $FailedItem = $_.Exception.ItemName
    # optional script for getting notification on mail
    $EmailFrom = “[email protected]
    $EmailTo = “[email protected]
    $Subject = “Notification for Server Job Failed Replication on 10.163.24.10 Server”
    $Body = “We failed to upload file $FailedItem. The error message was $ErrorMessage” $SMTPServer = “smtp.gmail.com”
    $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
    $SMTPClient.EnableSsl = $true
    $SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“[email protected] il.com”, “xxxx”); $SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)



    Break
    }
    Finally
    {
    $Time=Get-Date
    “This script made a Upload attempt at $Time” | out-file c:\logs\ExpensesScript.log -append
    }










    Last edited by sameer12; 16th July 2017, 17:46.

  • #2
    How are you running the script? If it is in the ISE you have limited breakpoints and debugging
    Tom Jones
    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
    PhD, MSc, FIAP, MIITT
    IT Trainer / Consultant
    Ossian Ltd
    Scotland

    ** Remember to give credit where credit is due and leave reputation points where appropriate **

    Comment

    Working...
    X