forked from DeploymentResearch/DRFiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPowerShell-Template.ps1
125 lines (96 loc) · 3.54 KB
/
PowerShell-Template.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# Name: PowerShell Template
# Description: Standard PowerShell template
# Author:
try
{
Function Main
{
# Function Started
LogTraceMessage "*** Function Main Started ***"
Write-Verbose "*** Function Main Started ***"
# Set Global Environment Variables (Inputs)
SetGlobalEnvVariables
# Import PS Modules
ImportPsModules
# Create and add more funcitons
# Function Finished
LogTraceMessage "*** Function Main Finished ***"
Write-Verbose "*** Function Main Finished ***"
}
Function SetGlobalEnvVariables
{
# Function Started
LogTraceMessage "*** Function SetGlobalEnvVariables Started ***"
Write-Verbose "*** Function SetGlobalEnvVariables Started ***"
# Base script variables. No modification should be necessary
# Set variables with global scope
$script:TraceState = ''
LogTraceMessage "Variable TraceState set to $script:TraceState"
Write-Verbose "Variable TraceState set to $script:TraceState"
$script:ErrorMessage = ''
LogTraceMessage "Variable ErrorMessage set to $script:ErrorMessage"
Write-Verbose "Variable ErrorMessage set to $script:ErrorMessage"
$script:ErrorState = 0
LogTraceMessage "Variable ErrorState set to $script:ErrorState"
Write-Verbose "Variable ErrorState set to $script:ErrorState"
#Script variables. Modify as necessary
$Script:LoggingPath = 'c:\Windows\Temp\Set-DriverPackageXML.log'
LogTraceMessage "Variable LoggingPath set to $script:LoggingPath"
Write-Verbose "Variable LoggingPath set to $script:LoggingPath"
# Add variables here
# Function Finished
LogTraceMessage "*** Function SetGlobalEnvVariables Finished ***"
Write-Verbose "*** Function SetGlobalEnvVariables Finished ***"
}
Function ImportPsModules
{
# Function Started
LogTraceMessage "*** Function ImportPsModules Started ***"
Write-Verbose "*** Function ImportPsModules Started ***"
# Function Finished
LogTraceMessage "*** Function ImportPsModules Finished ***"
Write-Verbose "*** Function ImportPsModules Finished ***"
}
Function LogTraceMessage ($strMessage)
{
[array]$script:TraceMessage += (Get-Date).ToString() + ': ' + $strMessage + '~~'
}
# Script Started
LogTraceMessage "*** Set Driver Pacakge XML ***"
Write-Verbose "*** Set Driver Pacakge XML ***"
#Main
Main
}
Catch
{
# Catch Started
LogTraceMessage "*** Catch Started ***"
Write-Verbose "*** Catch Started ***"
# Log error messages
$script:ErrorMessage = $Error[0].Exception.ToString()
LogTraceMessage "Variable ErrorMessage set to $script:ErrorMessage"
Write-Verbose "Variable ErrorMessage set to $script:ErrorMessage"
$script:ErrorState = 3
LogTraceMessage "Variable ErrorState set to $script:ErrorState"
Write-Verbose "Variable ErrorState set to $script:ErrorState"
# Catch Finished
LogTraceMessage "*** Catch Finished ***"
Write-Verbose "*** Catch Finished ***"
}
Finally
{
# Finally Started
LogTraceMessage "*** Finally Started ***"
Write-Verbose "*** Finally Started ***"
# Log Error State/Message
LogTraceMessage "Variable ErrorState = $script:ErrorState"
Write-Verbose "Variable ErrorState = $script:ErrorState"
# Finally Finished
LogTraceMessage "*** Finally Finished ***"
Write-Verbose "*** Finally Finished ***"
# Script Finished
LogTraceMessage "*** Name of script Finished ***"
Write-Verbose "*** name of script finished Finished ***"
# Write to log file
$script:TraceMessage | Out-File $script:LoggingPath
}