Skip to content

Commit 8882c1d

Browse files
added agent job failure
1 parent ed049c1 commit 8882c1d

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

agentjobstofileproperly.ps1

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## This needs to be run as a file available to the agent service
2+
3+
## as a SQLCMD step
4+
5+
## powershell.exe 'path to file'
6+
7+
Write-Output "Starting Copy of XXXX database from SourceServerName to DestServerName"
8+
9+
try {
10+
$params = @{
11+
Source = ''
12+
Destination = ''
13+
Database = ''
14+
BackupRestore = $true
15+
NetworkShare = ''
16+
WithReplace = $true
17+
EnableException = $true
18+
Verbose = $true
19+
}
20+
$output = Copy-DbaDatabase @Params
21+
}
22+
Catch
23+
{
24+
$CopyError = $error[0..5] | fl -force
25+
$CopyError = $CopyError | OUt-String
26+
Write-Error $CopyError
27+
28+
[System.Environment]::Exit(1)
29+
}
30+
if ($output.Status = 'Failed') {
31+
$CopyError = $error[0..5] | fl -force
32+
$CopyError = $CopyError | OUt-String
33+
Write-Error $CopyError
34+
[System.Environment]::Exit(1)
35+
}

0 commit comments

Comments
 (0)