update
This commit is contained in:
@@ -0,0 +1,44 @@
|
|||||||
|
## Set the MSP name and environment variable
|
||||||
|
$MSPName = "Emberkom"
|
||||||
|
|
||||||
|
## Set the name of the module to deploy
|
||||||
|
$ModuleName = "PSModule"
|
||||||
|
|
||||||
|
## Define base URL for downloading module file
|
||||||
|
$ModuleURL = "https://dev.emberkom.com/emberkom/management-scripts/raw/branch/master/${ModuleName}.psm1"
|
||||||
|
|
||||||
|
## Setup the MSP management directories
|
||||||
|
If ( Test-Path ${Env:ProgramData} )
|
||||||
|
{ $RootDir = "${Env:ProgramData}\${MSPName}" } Else { $RootDir = "${Env:SystemDrive}\${MSPName}" }
|
||||||
|
|
||||||
|
## Set the path to this module
|
||||||
|
$ModulePath = "${RootDir}\Scripts\${ModuleName}"
|
||||||
|
|
||||||
|
## Make sure all the management directories exist
|
||||||
|
If ( !(Test-Path $RootDir) )
|
||||||
|
{
|
||||||
|
Try { New-Item -Path $RootDir -ItemType Directory -Force | Out-Null }
|
||||||
|
Catch { Write-Output $_.Exception.Message }
|
||||||
|
}
|
||||||
|
If ( !(Test-Path "${RootDir}\Scripts") )
|
||||||
|
{
|
||||||
|
Try { New-Item -Path "${RootDir}\Scripts" -ItemType Directory -Force | Out-Null }
|
||||||
|
Catch { Write-Output $_.Exception.Message }
|
||||||
|
}
|
||||||
|
If ( !(Test-Path "${RootDir}\Tools") )
|
||||||
|
{
|
||||||
|
Try { New-Item -Path "${RootDir}\Tools" -ItemType Directory -Force | Out-Null }
|
||||||
|
Catch { Write-Output $_.Exception.Message }
|
||||||
|
}
|
||||||
|
If ( !(Test-Path "${RootDir}\Logs") )
|
||||||
|
{
|
||||||
|
Try { New-Item -Path "${RootDir}\Logs" -ItemType Directory -Force | Out-Null }
|
||||||
|
Catch { Write-Output $_.Exception.Message }
|
||||||
|
}
|
||||||
|
|
||||||
|
## Create environment variable for the root MSP directory
|
||||||
|
[System.Environment]::SetEnvironmentVariable('MSPDir',"${RootDir}",[System.EnvironmentVariableTarget]::Machine)
|
||||||
|
|
||||||
|
## Download the module file
|
||||||
|
Try { (New-Object Net.WebClient).DownloadFile($ModuleURL, "${RootDir}\Scripts\${ModuleName}\${ModuleName}.psm1") }
|
||||||
|
Catch { Write-Output $_.Exception.Message }
|
||||||
@@ -40,7 +40,7 @@ Function global:Set-WinEvtLog {
|
|||||||
Begin
|
Begin
|
||||||
{
|
{
|
||||||
# Keep track of changes made to event logs in a separate file.
|
# Keep track of changes made to event logs in a separate file.
|
||||||
$RecordLog = "${RecordKeepingDir}\WinEvtLogs-Enabled.log"
|
$RecordLog = "${Env:MSPLogs}\WinEvtLogs-Enabled.log"
|
||||||
|
|
||||||
If ( !(Test-Path -Path $RecordLog) )
|
If ( !(Test-Path -Path $RecordLog) )
|
||||||
{
|
{
|
||||||
|
|||||||
+3
-50
@@ -1,60 +1,13 @@
|
|||||||
#Requires -Version 2.0
|
#Requires -Version 2.0
|
||||||
|
|
||||||
## Set the MSP name
|
|
||||||
$MSPName = "Emberkom"
|
|
||||||
|
|
||||||
## Set the name of the environment variable used for locating this module
|
|
||||||
$MSPEnvVar = 'EKPSM'
|
|
||||||
|
|
||||||
## Set the name of this module
|
## Set the name of this module
|
||||||
$ModuleName = "PSModule"
|
$ModuleName = "PSModule"
|
||||||
|
|
||||||
## Define base URL for updating modules and resources
|
## Define base URL for updating modules and resources
|
||||||
$BaseURL = "https://dev.emberkom.com/emberkom/management-scripts/raw/branch/master/${ModuleName}"
|
$BaseURL = "https://dev.emberkom.com/emberkom/management-scripts/raw/branch/master/${ModuleName}"
|
||||||
|
|
||||||
## Setup the MSP management directory
|
|
||||||
If ( Test-Path ${Env:ProgramData} )
|
|
||||||
{ $RootDir = "${Env:ProgramData}\${MSPName}" } Else { $RootDir = "${Env:SystemDrive}\${MSPName}" }
|
|
||||||
|
|
||||||
$RecordKeepingDir = "${RootDir}\RecordKeeping"
|
|
||||||
$ScriptsDir = "${RootDir}\Scripts"
|
|
||||||
$ToolsDir = "${RootDir}\Tools"
|
|
||||||
$LogsDir = "${RootDir}\Logs"
|
|
||||||
|
|
||||||
## Function to create a directory and return an error if it fails
|
|
||||||
Function MakeDir
|
|
||||||
{
|
|
||||||
param([string]$Path)
|
|
||||||
Write-Output "Creating ${Path}"
|
|
||||||
Try { New-Item -Path $Path -ItemType Directory -Force | Out-Null }
|
|
||||||
Catch { Write-Output $_.Exception.Message }
|
|
||||||
}
|
|
||||||
|
|
||||||
## Make sure all the management directories exist
|
|
||||||
If ( !(Test-Path $RootDir) ) { MakeDir $RootDir }
|
|
||||||
If ( !(Test-Path $RecordKeepingDir) ) { MakeDir $RecordKeepingDir }
|
|
||||||
If ( !(Test-Path $ScriptsDir) ) { MakeDir $ScriptsDir }
|
|
||||||
If ( !(Test-Path $ToolsDir) ) { MakeDir $ToolsDir }
|
|
||||||
If ( !(Test-Path $LogsDir) ) { MakeDir $LogsDir }
|
|
||||||
|
|
||||||
## Set the path to this module
|
## Set the path to this module
|
||||||
$ModulePath = "${ScriptDir}\${ModuleName}"
|
$ModulePath = "${Env:MSPDir}\Scripts\${ModuleName}"
|
||||||
|
|
||||||
## Set the path to the module in an environment variable
|
|
||||||
[System.Environment]::SetEnvironmentVariable("${MSPEnvVar}", "${ModulePath}",[System.EnvironmentVariableTarget]::Machine)
|
|
||||||
|
|
||||||
## Update PATH to include the environment variable, if it's not already present
|
|
||||||
#$ListOfPaths = [System.Environment]::GetEnvironmentVariable('PATH')
|
|
||||||
#$SplitListOfPaths = $ListOfPaths.Split(';')
|
|
||||||
#$ModulePathPresent = $false
|
|
||||||
#$EnvVarString = '%{0}%' -f $MSPEnvVar
|
|
||||||
#ForEach ( $path in $SplitListOfPaths ) { If ( $path -eq $EnvVarString ) { $ModulePathPresent = $true } }
|
|
||||||
#If ( !($ModulePathPresent) )
|
|
||||||
#{
|
|
||||||
# ## Set the string to update PATH with
|
|
||||||
# $NewPathString = '{0};{1}' -f $EnvVarString,$ListOfPaths
|
|
||||||
# [System.Environment]::SetEnvironmentVariable('PATH', "${NewPathString}",[System.EnvironmentVariableTarget]::Machine)
|
|
||||||
#}
|
|
||||||
|
|
||||||
## Function to simply import a module and return an error message if it fails
|
## Function to simply import a module and return an error message if it fails
|
||||||
Function Load-Module
|
Function Load-Module
|
||||||
@@ -89,7 +42,7 @@ Function Get-Module
|
|||||||
## Download the new file, overwriting the local copy
|
## Download the new file, overwriting the local copy
|
||||||
If ( IsDownloadable $ModuleURL )
|
If ( IsDownloadable $ModuleURL )
|
||||||
{
|
{
|
||||||
Try { (New-Object Net.WebClient).DownloadFile($ModuleURL, $ModulePath) }
|
Try { (New-Object Net.WebClient).DownloadFile($ModuleURL, $FilePath) }
|
||||||
Catch { Write-Output $_.Exception.Message }
|
Catch { Write-Output $_.Exception.Message }
|
||||||
} Else { Write-Output "Could not download ${ModuleURL}" }
|
} Else { Write-Output "Could not download ${ModuleURL}" }
|
||||||
}
|
}
|
||||||
@@ -147,4 +100,4 @@ $ListOfModules = @(
|
|||||||
ForEach ($module in $ListOfModules) { Load-Module $module }
|
ForEach ($module in $ListOfModules) { Load-Module $module }
|
||||||
|
|
||||||
## Make sure this module exports only the functions that should be exported
|
## Make sure this module exports only the functions that should be exported
|
||||||
Export-ModuleMember -Function Log -Variable RecordKeepingDir, ScriptsDir, ToolsDir, LogsDir
|
Export-ModuleMember -Function Log
|
||||||
Reference in New Issue
Block a user