Install.ps1

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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<#
    .SYNOPSIS
        Download the module files from GitHub.
 
    .DESCRIPTION
        Download the module files from GitHub to the local client in the module folder.
#>


[CmdLetBinding()]
Param (
    [ValidateNotNullOrEmpty()]
    [String]$ModuleName = 'ImportExcel',
    [String]$InstallDirectory,
    [ValidateNotNullOrEmpty()]
    [String]$GitPath = 'https://raw.github.com/dfinke/ImportExcel/master'
)

Begin {
    Try {
        Write-Verbose "$ModuleName module installation started"

        $Files = @(
            'AddConditionalFormatting.ps1',
            'Charting.ps1',
            'ColorCompletion.ps1',
            'ConvertFromExcelData.ps1',
            'ConvertFromExcelToSQLInsert.ps1',
            'ConvertExcelToImageFile.ps1',
            'ConvertToExcelXlsx.ps1',
            'Copy-ExcelWorkSheet.ps1',
            'EPPlus.dll',
            'Export-charts.ps1',
            'Export-Excel.ps1',
            'Export-ExcelSheet.ps1',
            'formatting.ps1',
            'Get-ExcelColumnName.ps1',
            'Get-ExcelSheetInfo.ps1',
            'Get-ExcelWorkbookInfo.ps1',
            'Get-HtmlTable.ps1',
            'Get-Range.ps1',
            'Get-XYRange.ps1',
            'Import-Html.ps1',
            'ImportExcel.psd1',
            'ImportExcel.psm1',
            'InferData.ps1',
            'Invoke-Sum.ps1',
            'New-ConditionalFormattingIconSet.ps1',
            'New-ConditionalText.ps1',
            'New-ExcelChart.ps1',
            'New-PSItem.ps1',
            'Open-ExcelPackage.ps1',
            'Pivot.ps1',
            'plot.ps1',
            'Send-SqlDataToExcel.ps1',
            'Set-CellStyle.ps1',
            'Set-Column.ps1',
            'Set-Row.ps1',
            'SetFormat.ps1',
            'TrackingUtils.ps1',
            'Update-FirstObjectProperties.ps1'
        )
    }
    Catch {
        throw "Failed installing the module in the install directory '$InstallDirectory': $_"
    }
}

Process {
    Try {
        if (-not $InstallDirectory) {
            Write-Verbose "$ModuleName no installation directory provided"

            $PersonalModules = Join-Path -Path ([Environment]::GetFolderPath('MyDocuments')) -ChildPath WindowsPowerShell\Modules

            if (($env:PSModulePath -split ';') -notcontains $PersonalModules) {
                Write-Warning "$ModuleName personal module path '$PersonalModules' not found in '`$env:PSModulePath'"
            }

            if (-not (Test-Path $PersonalModules)) {
                Write-Error "$ModuleName path '$PersonalModules' does not exist"
            }

            $InstallDirectory = Join-Path -Path $PersonalModules -ChildPath $ModuleName
            Write-Verbose "$ModuleName default installation directory is '$InstallDirectory'"
        }

        if (-not (Test-Path $InstallDirectory)) {
            New-Item -Path $InstallDirectory -ItemType Directory -EA Stop | Out-Null
            Write-Verbose "$ModuleName created module folder '$InstallDirectory'"
        }

        $WebClient = New-Object System.Net.WebClient
        
        $Files | ForEach-Object {
            $WebClient.DownloadFile("$GitPath/$_","$installDirectory\$_")
            Write-Verbose "$ModuleName installed module file '$_'"
        }

        Write-Verbose "$ModuleName module installation successful"
    }
    Catch {
        throw "Failed installing the module in the install directory '$InstallDirectory': $_"
    }
}