Files
management-scripts/Deploy-PSModule.ps1
T
2020-08-14 14:19:37 -04:00

55 lines
2.0 KiB
PowerShell

## 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}/${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 and make the directory for it
$ModulePath = "${RootDir}\Scripts\${ModuleName}"
## Create the path to the module
If ( !(Test-Path $ModulePath) )
{
Try { New-Item -Path $ModulePath -ItemType Directory -Force | Out-Null }
Catch { Write-Output $_.Exception.Message }
}
## Set the environment variable to the module
[System.Environment]::SetEnvironmentVariable('MSPPSModule',"${RootDir}\Scripts\${ModuleName}",[System.EnvironmentVariableTarget]::Machine)
## 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 }