How can i pause the script to see error

Home Forums Scripting PowerShell How can i pause the script to see error

This topic contains 1 reply, has 2 voices, and was last updated by  Ossian 1 year, 4 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts

  • sameer12
    Member
    #167106

    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 = “[URL=”ftp://xxx:xx1/dir/%C2%94″]ftp://xxx:xx1/dir/”[/URL]
    $ftp = “[URL=”ftp://xx.xx.xx:xx/%C2%94″]ftp://xx.xx.xx:xx/”[/URL]
    #$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:logsExpensesScript.log -append
    }


    Ossian
    Moderator
    #191745

    How are you running the script? If it is in the ISE you have limited breakpoints and debugging

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.