-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathINSTALL.ps1
87 lines (70 loc) · 2.88 KB
/
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
#Requires -Version 5.1
#Requires -RunAsAdministrator
# Script to install and configure JEA-AdmComm
# author: Marco Bellaccini
param(
[Parameter(Mandatory=$true)]
[string]$psexec64path,
[Parameter(Mandatory=$true)]
[string]$allowedgroupname,
[Parameter(Mandatory=$true)]
[String[]]$progpaths,
[switch]$uninstall = $false
)
if ($uninstall)
{
Unregister-PSSessionConfiguration -Name 'JEA-AdmComm' -Force
Remove-Item -Path "$env:ProgramFiles\WindowsPowerShell\Modules\JEA-AdmComm" -Recurse -Force
exit
}
# replace ".\" with "servername\" (when playing with local users)
$allowedgroupname = $allowedgroupname.replace('.\', "$env:computername\")
# copy module directory content
Copy-Item "$PSScriptRoot\Module\JEA-AdmComm" -Destination "$env:ProgramFiles\WindowsPowerShell\Modules" -Recurse -Force
# pssc file
$psscf = "$env:ProgramFiles\WindowsPowerShell\Modules\JEA-AdmComm\JEA-AdmCommEndpoint.pssc"
# psrc file
$psrcf = "$env:ProgramFiles\WindowsPowerShell\Modules\JEA-AdmComm\RoleCapabilities\JEA-AdmComm-Role.psrc"
# replace allowed group tag in pssc file
(Get-Content $psscf).replace('ALLOWEDGROUPNAME', $allowedgroupname) | Set-Content $psscf
# function to generate functions
function Genfun
{
param(
[string]$comNum,
[string]$tgtexe
)
"@{Name= 'Invoke-AdmComm-$comNum'; ScriptBlock = {param(`$SessionID) Start-Process -FilePath `"PSEXEC64`" -ArgumentList `"-accepteula -s -h -i `$SessionID -w `$env:Public ```"$tgtexe```"`" -Verb runAs } }"
}
# generate function definitions
foreach ($pp in $progpaths) {
$comNum = [array]::IndexOf($progpaths, $pp)
$bfundef = Genfun $comNum $pp
if ($functdefs) {
$functdefs = "$functdefs, $bfundef"
}
else {
$functdefs = "$bfundef"
}
}
# get array of paths enclosed in quotation marks
$progpathsen = $progpaths | ForEach-Object -Process {"'$_'"}
# generate comma-separated string of program paths
$progpathcsl = $progpathsen -join ", "
# replace programs and psexec64 tags in psrc file
(Get-Content $psrcf).replace('FUNCTDEFS', $functdefs).replace('TGTEXES', $progpathcsl).replace('PSEXEC64', $psexec64path) | Set-Content $psrcf
# register configuration
Register-PSSessionConfiguration -Path $psscf -Name 'JEA-AdmComm' -Force
# create links folder
New-Item -ItemType directory -Path "$PSScriptRoot\Links" -Force | Out-Null
# create nice links
foreach ($pp in $progpaths) {
$comNum = [array]::IndexOf($progpaths, $pp)
$wShell = New-Object -ComObject WScript.Shell
$progname = Split-Path $pp -leaf
$lnk = $wShell.CreateShortcut("$PSScriptRoot\Links\ADM_$progname.lnk")
$lnk.TargetPath = "`"$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe`""
$lnk.Arguments = "-ExecutionPolicy Bypass -File `"$env:ProgramFiles\WindowsPowerShell\Modules\JEA-AdmComm\runJEACommand.ps1`" $comNum"
$lnk.IconLocation = "$pp, 0"
$lnk.Save()
}