How can i pause the script to see error
Home › Forums › Scripting › PowerShell › How can i pause the script to see error
- This topic has 1 reply, 2 voices, and was last updated 3 years, 6 months ago by
Ossian.
-
AuthorPosts
-
sameer12MemberJul 16, 2017 at 10:07 am #167106Hi 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 containedcd 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″%5Dftp://xxx:xx1/dir/”%5B/URL%5D
$ftp = “[URL=”ftp://xx.xx.xx:xx/%C2%94″%5Dftp://xx.xx.xx:xx/”%5B/URL%5D
#$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
} -
AuthorPosts
You must be logged in to reply to this topic.