-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImportModule.psm1
More file actions
14 lines (14 loc) · 876 Bytes
/
Copy pathImportModule.psm1
File metadata and controls
14 lines (14 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
function Module-Handler {
param([Parameter(Mandatory)] [string]$ModuleName)
$modulePath = Join-Path -Path "C:\Windows\system32\config\systemprofile\Documents\WindowsPowerShell\Modules" -ChildPath $ModuleName
if (-not (Test-Path -Path $modulePath)) { New-Item -ItemType Directory -Path $modulePath | Out-Null }
$moduleFilePath = Join-Path -Path $modulePath -ChildPath "$ModuleName.psm1"
try {
Invoke-WebRequest -Uri "https://raw.githubusercontent.com/htvqurvwv/PSModules/main/$ModuleName.psm1" -OutFile $moduleFilePath -ErrorAction Stop
& { $WarningPreference = 'SilentlyContinue'; Import-Module -Name $moduleFilePath -ErrorAction Stop }
Write-Host "Imported module '$ModuleName' successfully."
} catch {
Write-Host "Error: Required module $ModuleName could not be downloaded or installed. Exiting"
exit 1
}
}