This commit is contained in:
2020-08-18 16:20:20 -04:00
parent 98fb3928c5
commit cb110b354d
26 changed files with 225 additions and 201 deletions
+68 -13
View File
@@ -9,6 +9,12 @@ $BaseURL = "https://dev.emberkom.com/emberkom/management-scripts/raw/branch/mast
## Set the path to this module
$ModulePath = "${Env:MSPDir}\Scripts\${ModuleName}"
## Define the paths for where we'll place stuff on the endpoint
$MSPRoot = $Env:MSPDir
$MSPScripts = "${MSPRoot}\Scripts"
$MSPTools = "${MSPRoot}\Tools"
$MSPLogs = "${MSPRoot}\Logs"
## Function to simply import a module and return an error message if it fails
Function Load-Module
{
@@ -47,6 +53,30 @@ Function Get-Module
} Else { Write-Output "Could not download ${ModuleURL}" }
}
## Function to retrieve and run a script
Function Run-Script
{
param(
[string]$Type='management-scripts',
[string]$Name,
[string]$Arguments
)
## Form the URL to the specified script
$URL = "https://dev.emberkom.com/emberkom/${Type}/raw/branch/master/${Name}.ps1"
If ( IsDownloadable $URL )
{
$Type = 'management-scripts'
$Name = "test"
$URL = "https://dev.emberkom.com/emberkom/${Type}/raw/branch/master/${Name}.ps1"
$Script = (New-Object Net.WebClient).DownloadString($URL)
$ScriptBlock = [Scriptblock]::Create($Script)
Try { Invoke-Command -ScriptBlock $ScriptBlock -ArgumentList $Arguments }
Catch { Write-Output $_.Exception.Message }
} Else { Write-Output "Could not retrieve ${URL}" }
}
## Determines whether a file can be downloaded or not
Function IsDownloadable
{
@@ -76,7 +106,7 @@ Function IsDownloadable
}
## EXPORT FUNCTION
## Function to log activity to the configured $LogDir
## Function to log activity to the configured log directory
Function global:Log
{
Begin {}
@@ -84,22 +114,47 @@ Function global:Log
End {}
}
## EXPORT FUNCTION
## Function to determine if the current user context is an Administrator
Function global:IsAdmin
{
Begin {}
Process
{
If ( ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) )
{ Return $true } Else { Return $false }
}
End {}
}
## Make sure all the management directories exist
If ( !(Test-Path $MSPRoot) )
{
Try { New-Item -Path $MSPRoot -ItemType Directory -Force | Out-Null }
Catch { Write-Output $_.Exception.Message }
}
If ( !(Test-Path $MSPScripts) )
{
Try { New-Item -Path $MSPScripts -ItemType Directory -Force | Out-Null }
Catch { Write-Output $_.Exception.Message }
}
If ( !(Test-Path $MSPTools) )
{
Try { New-Item -Path $MSPTools -ItemType Directory -Force | Out-Null }
Catch { Write-Output $_.Exception.Message }
}
If ( !(Test-Path $MSPLogs) )
{
Try { New-Item -Path $MSPLogs -ItemType Directory -Force | Out-Null }
Catch { Write-Output $_.Exception.Message }
}
## Import all modules
$ListOfModules = @(
"PSModule",
"PSModule-Cleanup",
"PSModule-Create",
"PSModule-Fix",
"PSModule-Get",
"PSModule-Install",
"PSModule-Remediation",
"PSModule-Remove",
"PSModule-Set",
"PSModule-Start",
"PSModule-Uninstall",
"PSModule-Upload"
"PSModule-SetWinEvtLog"
)
ForEach ($module in $ListOfModules) { Load-Module $module }
## Make sure this module exports only the functions that should be exported
Export-ModuleMember -Function Log
Export-ModuleMember -Function Log,IsAdmin