-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathInstall-IntuneStack.ps1
More file actions
90 lines (74 loc) · 2.44 KB
/
Copy pathInstall-IntuneStack.ps1
File metadata and controls
90 lines (74 loc) · 2.44 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
<#
.SYNOPSIS
Installs the IntuneStack module from GitHub.
.DESCRIPTION
Clones the IntuneStack repository and creates a symbolic link to the module
folder in the user's PowerShell module path, following the pattern from
Practical Automation with PowerShell (Dowst, 2023).
.EXAMPLE
Invoke-Expression (Invoke-RestMethod -Uri 'https://raw.githubusercontent.com/AllwaysHyPe/IntuneStack/refs/heads/main/Install-IntuneStack.ps1')
#>
$RepoUrl = 'https://github.com/AllwaysHyPe/IntuneStack.git'
function Test-CmdInstall {
param(
$TestCommand
)
try {
$Before = $ErrorActionPreference
$ErrorActionPreference = 'Stop'
$testResult = Invoke-Expression -Command $TestCommand
} catch {
$testResult = $null
} finally {
$ErrorActionPreference = $Before
}
$testResult
}
function Set-EnvPath {
$env:Path =
[System.Environment]::GetEnvironmentVariable("Path", "Machine") +
";" +
[System.Environment]::GetEnvironmentVariable("Path", "User")
}
$GitVersion = Test-CmdInstall 'git --version'
if (-not $GitVersion) {
if ($IsWindows) {
Write-Host "Installing Git for Windows..."
$wingetParams = 'winget install --id Git.Git' +
' -e --source winget --accept-package-agreements' +
' --accept-source-agreements'
Invoke-Expression $wingetParams
} elseif ($IsLinux) {
Write-Host "Installing Git for Linux..."
apt-get install git -y
} elseif ($IsMacOS) {
Write-Host "Installing Git for macOS..."
brew install git
}
Set-EnvPath
$GitVersion = Test-CmdInstall 'git --version'
if (-not $GitVersion) {
throw "Unable to locate git. Please install manually and rerun this script."
}
Write-Host "Git $GitVersion installed"
} else {
Write-Host "Git $GitVersion already installed"
}
if ($IsWindows) {
Set-Location $env:USERPROFILE
} else {
Set-Location $env:HOME
}
Invoke-Expression -Command "git clone $RepoUrl"
# The module folder is the IntuneStack subfolder inside the cloned repo
$ModuleFolder = Get-Item './IntuneStack'
$UserPowerShellModules =
[Environment]::GetEnvironmentVariable("PSModulePath").Split(';')[0]
$SimLinkProperties = @{
ItemType = 'SymbolicLink'
Path = Join-Path $UserPowerShellModules 'IntuneStack'
Target = $ModuleFolder.FullName
Force = $true
}
New-Item @SimLinkProperties
Write-Host "IntuneStack installed. Run 'Import-Module IntuneStack' to get started."