-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstallDoITGeneralFunctions.ps1
More file actions
118 lines (107 loc) · 3.57 KB
/
InstallDoITGeneralFunctions.ps1
File metadata and controls
118 lines (107 loc) · 3.57 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
[CmdletBinding()]Param (
[Parameter(
Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)]
[ValidatePattern("^DOIT")]
[String[]]$ComputerName
)
$ModuleName = "DoIT.GeneralFunctions"
$GitHubUri = "https://github.com/jacobdonais/DoIT.GeneralFunctions/archive/master.zip"
$ResourceLocation = "./"
$ZipName = "master.zip"
if (Test-Path -Path ($ResourceLocation + $ZipName)) {
Write-Verbose "Removing exisiting zip file"
try {
Remove-Item -Path ($ResourceLocation + $ZipName) -Recurse -Force -Confirm:$false
Write-Verbose ".Successfully removed the existing zip file"
}
catch {
Write-Warning "Failed to remove the exisiting zip file"
break
}
}
Write-Verbose "Extracting module from GitHub"
try {
Invoke-WebRequest -Uri $GitHubUri -UseBasicParsing -OutFile ($ResourceLocation + $ZipName)
Write-Verbose ".Successfully extracted module from GitHub"
}
catch {
Write-Warning "Failed to extract module from GitHub"
break
}
if (Test-Path -Path "$($ResourceLocation)$($ModuleName)-master") {
Write-Verbose "Removing exisiting extracted zip file"
try {
Remove-Item -Path "$($ResourceLocation)$($ModuleName)-master" -Recurse -Force -Confirm:$false
Write-Verbose ".Successfully removed the existing extracted zip file"
}
catch {
Write-Warning "Failed to remove the exisiting extracted zip file"
break
}
}
Write-Verbose "Extracting zip file"
try {
Expand-Archive -Path ($ResourceLocation + $ZipName) -DestinationPath $ResourceLocation
Write-Verbose ".Successfully extracted zip file"
}
catch {
Write-Warning "Failed to extract zip file"
break
}
Write-Verbose "Removing zip file"
try {
Remove-Item -Path ($ResourceLocation + $ZipName) -Recurse -Force -Confirm:$false
Write-Verbose ".Successfully removed zip file"
}
catch {
Write-Warning "Failed to remove zip file"
break
}
foreach ($Computer in $ComputerName) {
Write-Verbose "Performing action on $Computer"
$InstallPath = "\\$Computer\C$\Program Files\WindowsPowerShell\Modules"
if (Test-Path -Path ($InstallPath + "\" + $ModuleName)) {
Write-Verbose "..Removing exisiting module"
try {
Remove-Item -Path ($InstallPath + "\" + $ModuleName) -Recurse -Force -Confirm:$false
Write-Verbose "...Successfully removed the module"
}
catch {
Write-Warning "Failed to remove the exisiting module on $Computer"
break
}
}
if (Test-Path -Path $InstallPath) {
Write-Verbose "..Downloading module to module path"
try {
Copy-Item -Path "$($ResourceLocation)$($ModuleName)-master\$($ModuleName)" -Destination $InstallPath -Recurse -Force -Confirm:$false
Write-Verbose "...Successfully downloaded the module"
}
catch {
Write-Warning "Failed to download module on $Computer"
break
}
}
else {
Write-Warning "Install Path does not exist on $Computer"
break
}
Write-Verbose "..Confirming module installed correctly"
if (Test-Path -Path ("$InstallPath\$ModuleName")) {
Write-Verbose "...Successfully installed module"
}
else {
Write-Warning "Module did not install on $Computer"
}
}
Write-Verbose "Removing resource files"
try {
Remove-Item -Path "$($ResourceLocation)$($ModuleName)-master" -Recurse -Force -Confirm:$false
Write-Verbose ".Successfully removed resource files"
}
catch {
Write-Warning "Failed to remove resource files"
break
}