cEPRSSSIS.psm1

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
[DscResource()]class cEPRSCopyDTSXSSIS
{
    [DscProperty()]$FilePath
    [DscProperty(Key)][string]$FileName
    [DscProperty()]$DestinationPath
    [DscProperty()]$DTUtilPath
    [cEPRSCopyDTSXSSIS]Get()
    {
        $FileContent = Get-Item -Path "$($this.FilePath)\$($this.FileName)"
        $this.FilePath = $FileContent.FullName
        return $this
    }
    [bool]Test()
    {
        if(Test-Path "$($this.DTUtilPath)\dtutil.exe")
        {
            if(Test-Path "$($this.FilePath)\$($this.FileName)")
            {
                $result = $false
            }
            else
            {
                Write-Warning "$($this.FilePath)\$($this.FileName) doesn't exist... Please check the path"
                Write-Verbose "$($this.FilePath)\$($this.FileName) doesn't exist... Please check the path"
                $result = $true
            }
        }
        else
        {
            Write-Warning "$($this.DTUtilPath) doesn't exist... Please check the path"
            Write-Verbose "$($this.DTUtilPath) doesn't exist... Please check the path"
            $result = $true
        }
        return $result
    }
    Set()
    {
        Write-Verbose "Set-Location $($this.DTUtilPath)"
        Set-Location "$($this.DTUtilPath)"
        .\dtutil.exe "/FExists SQL;\$($this.DestinationFolder)"
        if($env:LASTEXITCODE -eq $true)
        {
            .\dtutil.exe "/FCreate SQL;\;$($this.DestinationFolder)"
        }
        Write-Verbose "--------------------------------------------------------------"
        Write-Verbose "Copying '$($this.FilePath)\$($this.FileName)' package to SQL integration services."
        Write-Verbose "--------------------------------------------------------------" 
        $File=$this.FileName.split('.')[0]
        $Fullpath="$($this.FilePath)"+'\'+"$($this.FileName)"
        .\dtutil.exe "/FILE $Fullpath /COPY SQL;\$($this.DestinationFolder)\$File /QUIET"
    }
}