This commit is contained in:
2020-09-09 21:06:44 -04:00
parent d17435962a
commit 4d39099233
3 changed files with 211 additions and 173 deletions
+42 -23
View File
@@ -1,48 +1,64 @@
## Function to log activity to the configured log directory
Function global:Log
{
## Define some basic variables
$MSPName = "Emberkom"
## Setup the MSP management directories
If ( Test-Path ${Env:ProgramData} )
{ $MSPRoot = "${Env:ProgramData}\${MSPName}" } Else { $MSPRoot = "${Env:SystemDrive}\${MSPName}" }
$MSPScripts = "${MSPRoot}\Scripts"
$MSPTools = "${MSPRoot}\Tools"
$MSPLogs = "${MSPRoot}\Logs"
## Set a datestamp for any log files that might need to be created
$LogFilePrefix = Get-Date -Format "yyyyMMddHHmmss"
## Make sure all the management directories exist
If ( !(Test-Path $MSPRoot) )
{ New-Item -Path $MSPRoot -ItemType Directory -Force | Out-Null }
If ( !(Test-Path $MSPScripts) )
{ New-Item -Path $MSPScripts -ItemType Directory -Force | Out-Null }
If ( !(Test-Path $MSPTools) )
{ New-Item -Path $MSPTools -ItemType Directory -Force | Out-Null }
If ( !(Test-Path $MSPLogs) )
{ New-Item -Path $MSPLogs -ItemType Directory -Force | Out-Null }
## Function to log activity to the configured log directory
Function Log
{
param([string]$Message,[string]$LogName)
$LogEntry = "{0} - {1}" -f (Get-Date -Format "yyyy-MM-dd HH:mm:ss"),$Message
If ($LogName )
{
$LogFile = "${MSPLogs}\${LogFilePrefix}-${LogName}.log"
If (! (Test-Path $LogFile) ) { New-Item -Path $LogFile -ItemType File -Force | Out-Null }
Add-Content -Path $LogFile -Value $LogEntry
}
Write-Output $LogEntry
}
## Function to determine if the current user context is an Administrator
Function global:IsAdmin
Function IsAdmin
{
If ( ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) )
{ Return $true } Else { Return $false }
}
## Runs a script from the repo
Function global:Run-PSScript
Function Run-PSScript
{
param(
[string]$Type='management-scripts',
[string]$Name,
[string]$Arguments)
## Get rid of null arguments
param([string]$Type='management-scripts',[string]$Name,[string]$Arguments)
If ( $Arguments -eq "null" ) { $Arguments = $null }
## Make sure $Name and $Type are defined
If ( $Name -and $Type )
{
## Form the URL to the specified script
$URL = "https://dev.emberkom.com/emberkom/${Type}/raw/branch/master/${Name}.ps1"
## Get the script
Write-Output "Retrieving : ${Name}.ps1"
Try { $Script = (New-Object Net.WebClient).DownloadString($URL) }
Catch { Write-Output $_.Exception.Message }
## Make a script block
Try { $ScriptBlock = [Scriptblock]::Create($Script) }
Catch { Write-Output $_.Exception.Message }
## Run the script any any arguments
Write-Output "Executing: ${Name}.ps1 ${Arguments}"
Try { Invoke-Command -ScriptBlock $ScriptBlock -ArgumentList $Arguments }
Catch { Write-Output $_.Exception.Message }
}
Else { Write-Output "No script or type was specified" }
} Else { Write-Output "No script or type was specified" }
}
## Function to return a Powershell version object from a string
@@ -99,4 +115,7 @@ switch ($PSCmdlet.ParameterSetName)
'le' { If ( $WindowsBuild -le $le ) { Return $true } Else { Return $false } }
'eq' { If ( $WindowsBuild -eq $eq ) { Return $true } Else { Return $false } }
}
}
}
Function Write([string]$msg)
{ Write-Output "Called by: ${msg}" }