-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQL-asJob.ps1
More file actions
33 lines (30 loc) · 952 Bytes
/
SQL-asJob.ps1
File metadata and controls
33 lines (30 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Function RebuildPaths ($ServerInstance){
$SP_RebuildPaths = @"
USE [IODC_Central]
GO
DECLARE @RC int
DECLARE @Include_Drawings bit
SET @Include_Drawings = 0
EXECUTE @RC = [dbo].[Job_Cache_Partition_Paths_Set] @Include_Drawings
"@
$job = "RebuildPaths"
Get-Job $job | Remove-Job -Force -ErrorAction SilentlyContinue
$SqlParams = @{
ServerInstance = $ServerInstance
Database = "IODC_Central"
Query = $SP_RebuildPaths
OutputSqlErrors = $true
ErrorVariable = "SQL_Error"
QueryTimeout = 300
}
$ImportParams = @{
Name = "SQLPS"
ErrorAction = "SilentlyContinue"
DisableNameChecking = $true
}
Start-Job -ScriptBlock{
param($ImportParams, $SqlParams)
Import-Module @ImportParams
Invoke-Sqlcmd @SqlParams
} -Name $job -ArgumentList ($ImportParams, $SqlParams) #-ComputerName $env:COMPUTERNAME
}