-
Notifications
You must be signed in to change notification settings - Fork 1
/
pwsh_webserver_create_module.ps1
89 lines (75 loc) · 3.34 KB
/
pwsh_webserver_create_module.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#
# Pieter De Ridder
# Create a new webserver plugin (Powershell Module).
#
# created : 02/11/2020
# changed : 07/11/2020
#
# global vars
$global:WorkFolder = $($PSScriptRoot)
$global:WebPluginsPath = "$($global:WorkFolder)\plugins"
# create plugins folder
If (-Not (Test-Path $global:WebPluginsPath)) {
New-Item $global:WebPluginsPath -ItemType Directory
}
[string]$NewPluginName = Read-Host -Prompt "Enter Webserver Plugin Name (ex.: Web.MyPlugin)"
[string]$NewPluginDesc = Read-Host -Prompt "Enter Plugin Description"
[string]$NewPluginAuthor = Read-Host -Prompt "Enter Plugin Author Name"
# sanity checks
If ([string]::IsNullOrEmpty($NewPluginName)) {
Write-Warning "You must provide a Plugin name!"
Exit(-1)
}
# set default Author name
If ([string]::IsNullOrEmpty($NewPluginAuthor)) {
$NewPluginAuthor = [environment]::GetEnvironmentVariable("USERNAME")
}
# create module manifest file
If (-Not (Test-Path "$($global:WebPluginsPath)\$($NewPluginName)")) {
New-Item "$($global:WebPluginsPath)\$($NewPluginName)" -ItemType Directory
[string]$manifestFilename = "$($global:WebPluginsPath)\$($NewPluginName)\$($NewPluginName).psd1"
[string]$moduleFilename = "$($global:WebPluginsPath)\$($NewPluginName)\$($NewPluginName).psm1"
[string]$guid = $(New-Guid)
# create the meta file
$params = @{
Path = $manifestFilename
RootModule = $(Split-Path $moduleFilename -Leaf)
ModuleVersion = '1.0.0.0'
Guid = $guid
Author = $($NewPluginAuthor)
Description = $($NewPluginDesc)
#RequiredModules = @("Web.Global")
}
New-ModuleManifest @params
# create empty module file
New-Item -Path $moduleFilename -ItemType File
# add some content already
[string]$timeStampCreated = $(Get-Date).ToString("dd/MM/yyyy")
Add-Content -Path $moduleFilename -Value ""
Add-Content -Path $moduleFilename -Value "#"
Add-Content -Path $moduleFilename -Value "# $($NewPluginAuthor)"
Add-Content -Path $moduleFilename -Value "# $($NewPluginDesc)"
Add-Content -Path $moduleFilename -Value "#"
Add-Content -Path $moduleFilename -Value "# created : $($timeStampCreated)"
Add-Content -Path $moduleFilename -Value "# changed : $($timeStampCreated)"
Add-Content -Path $moduleFilename -Value "#"
Add-Content -Path $moduleFilename -Value ""
Add-Content -Path $moduleFilename -Value '$CommandsToExport = @()'
Add-Content -Path $moduleFilename -Value ""
Add-Content -Path $moduleFilename -Value "#"
Add-Content -Path $moduleFilename -Value "# Function : Invoke-HelloWorld"
Add-Content -Path $moduleFilename -Value "#"
Add-Content -Path $moduleFilename -Value "Function Invoke-HelloWorld {"
Add-Content -Path $moduleFilename -Value ' Write-Output "Hello"'
Add-Content -Path $moduleFilename -Value "}"
Add-Content -Path $moduleFilename -Value '$CommandsToExport += "Invoke-HelloWorld"'
Add-Content -Path $moduleFilename -Value ""
Add-Content -Path $moduleFilename -Value ""
Add-Content -Path $moduleFilename -Value 'Export-ModuleMember -Function $CommandsToExport'
Add-Content -Path $moduleFilename -Value ""
Write-Host "Webserver Plugin has been created!"
} else {
Write-Warning "Webserver Plugin with same name already present!"
Exit(-1)
}
Exit(0)