-
Notifications
You must be signed in to change notification settings - Fork 0
/
New-VMDPSModule.ps1
111 lines (95 loc) · 3.81 KB
/
New-VMDPSModule.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<#
.SYNOPSIS
This is a helper script for deployment process
.DESCRIPTION
Use this script to build psd1 file, install to local PowerShell Module directory and update File paths including Linux
#>
param (
[Parameter(Mandatory = $false)]
[ValidateScript({Test-Path $_})]
$AzureStorageConfigXMLPath
)
function Use-RunAs
{
# Check if script is running as Adminstrator and if not use RunAs
# Use Check Switch to check if admin
param([Switch]$Check)
$IsAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()`
).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
if ($Check) { return $IsAdmin }
if ($MyInvocation.ScriptName -ne "")
{
if (-not $IsAdmin)
{
try
{
$arg = "-file `"$($MyInvocation.ScriptName)`""
Start-Process "$psHome\powershell.exe" -Verb Runas -ArgumentList $arg -ErrorAction 'stop'
}
catch
{
Write-Warning "Error - Failed to restart script with runas"
break
}
exit # Quit this session of powershell
}
}
else
{
Write-Warning "Error - Script must be saved as a .ps1 file first"
break
}
}
function New-VMDManifest
{
New-ModuleManifest -Path $PSScriptRoot\VMD\VMD.psd1 `
-RootModule VMD.psm1 `
-Author 'Dennis Hobmaier' `
-CompanyName 'Solutions2Share' `
-Description 'Manage VMD VMs in Azure' `
-ModuleVersion '4.2' `
-RequiredModules 'AzureRM.Profile','AzureRM.Storage','AzureRM.Compute', 'AzureRM.Network', 'AzureRM.Resources' `
-FunctionsToExport 'Connect-VMD','Start-VMD','Stop-VMD','Select-VMDAzureSubscription',`
'New-VMDInstance','Get-VMDStatus','Get-VMDResourceGroup','Select-VMDResourceGroup','New-VMDVM', `
'Set-VMNetworkConfiguration','Set-Pagefile','Reset-VMDAuthentication' `
-CmdletsToExport '' `
-AliasesToExport ''
}
function New-VMDManifestLinux
{
New-ModuleManifest -Path $PSScriptRoot\VMDACC\VMD.psd1 `
-RootModule VMD.psm1 `
-Author 'Dennis Hobmaier' `
-CompanyName 'Solutions2Share' `
-Description 'Manage VMD VMs in Azure' `
-ModuleVersion '4.2' `
-RequiredModules 'Az.Accounts','Az.Storage', 'Az.Compute', 'Az.Network', 'Az.Resources' `
-FunctionsToExport 'Connect-VMD','Start-VMD','Stop-VMD','Select-VMDAzureSubscription',`
'New-VMDInstance','Get-VMDStatus','Get-VMDResourceGroup','Select-VMDResourceGroup','New-VMDVM', `
'Set-VMNetworkConfiguration','Set-Pagefile','Reset-VMDAuthentication' `
-CmdletsToExport '' `
-AliasesToExport ''
}
#Check if admin - no need, running user based installation
#Use-RunAs
Write-host 'Create new Manifest'
New-VMDManifest
Write-host 'Create new ManifestLinux'
New-VMDManifestLinux
Copy-Item -path $PSScriptRoot\VMD\VMDFunctions.ps1 -Destination $PSScriptRoot\VMDACC\VMDFunctions.ps1
#"Script Running As Administrator"
Write-host 'Installing VMD PowerShell Module'
# Global Install
# Copy-Item $PSScriptRoot\UDESetup $Env:ProgramFiles\WindowsPowerShell\Modules\ -Force -Recurse
$paths = $env:PSModulePath.Split(';')
foreach ($path in $paths)
{
if (($path.Indexof('\Users\')) -gt 0 -and ($path.Indexof('OfficeDevPnP') -lt 0) -and ($path.Indexof('SharePointPnPPowerShellOnline') -lt 0) -and ($path.Indexof('.vscode') -lt 0))
{
Write-Host 'Install PowerShell Module to ' $path
Copy-Item $PSScriptRoot\VMD $path -Force -Recurse -ErrorAction stop
If ($AzureStorageConfigXMLPath) {Copy-Item $AzureStorageConfigXMLPath -Destination $path\VMD\VMD-Config.xml -Force}
}
}
Write-host 'Done' -ForegroundColor Green
Start-Sleep -Seconds 5