mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-07-01 10:32:35 -05:00
refractor
- refractor scans into one function - create Invoke-WinUtilInitializeModule Function & use it accordingly - refractor Update Installation process - refractor DataGrid Item-management through Itemsource for better Main Thread performance
This commit is contained in:
28
functions/public/Invoke-WinUtilInitializeModule.ps1
Normal file
28
functions/public/Invoke-WinUtilInitializeModule.ps1
Normal file
@ -0,0 +1,28 @@
|
||||
function Invoke-WinUtilInitializeModule {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Initializes and imports a specified PowerShell module.
|
||||
|
||||
.PARAMETER module
|
||||
The name of the module to be installed and imported. If the module is not already available, it will be installed for the current user.
|
||||
|
||||
#>
|
||||
|
||||
param (
|
||||
[string]$module
|
||||
)
|
||||
|
||||
Invoke-WPFRunspace -ArgumentList $module -DebugPreference $DebugPreference -ScriptBlock {
|
||||
param ($module)
|
||||
try {
|
||||
if (-not (Get-Module -ListAvailable -Name $module)) {
|
||||
Write-Host "Installing $module module..."
|
||||
Install-Module -Name $module -Force -Scope CurrentUser
|
||||
}
|
||||
Import-Module $module -ErrorAction Stop
|
||||
Write-Host "Imported $module module successfully"
|
||||
} catch {
|
||||
Write-Host "Error importing $module module: $_" -ForegroundColor Red
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user