-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPSScriptTemplate.ps1
99 lines (73 loc) · 3.28 KB
/
PSScriptTemplate.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
#requires -version 2
<#
.SYNOPSIS
<None>
.DESCRIPTION
<None>
.INPUTS
<None>
.OUTPUTS
Create transcript log file similar to $ScriptDir\[SCRIPTNAME]_[YYYY_MM_DD]_[HHhMMmSSs].log
Create a list of SUBJECT, similar to $ScriptDir\[SCRIPTNAME]_SUBJECT_[YYYY_MM_DD]_[HHhMMmSSs].csv
.NOTES
Version: 0.1
Author: ALBERT Jean-Marc
Creation Date: DD/MM/YYYY (DD/MM/YYYY)
Purpose/Change: 1.0 - YYYY.MM.DD - ALBERT Jean-Marc - Initial script development
.SOURCES
<None>
.EXAMPLE
<None>
#>
#region ---------------------------------------------------------[Initialisations]--------------------------------------------------------
Set-StrictMode -version Latest
#Set Error Action to Silently Continue
$ErrorActionPreference = "SilentlyContinue"
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
$scriptFile = $MyInvocation.MyCommand.Definition
$launchDate = get-date -f "yyyy.MM.dd-HHhmmmss"
$logDirectoryPath = $scriptPath + "\" + $launchDate
$buffer = "$scriptPath\bufferCommand.txt"
$fullScriptPath = (Resolve-Path -Path $buffer).Path
$loggingFunctions = "$scriptPath\logging\Logging.ps1"
$utilsFunctions = "$scriptPath\utilities\Utils.ps1"
$addsFunctions = "$scriptPath\utilities\ADDS.ps1"
#endregion
#region ----------------------------------------------------------[Declarations]----------------------------------------------------------
$scriptName = [System.IO.Path]::GetFileName($scriptFile)
$scriptVersion = "0.1"
if(!(Test-Path $logDirectoryPath)) {
New-Item $logDirectoryPath -type directory | Out-Null
}
$logFileName = "Log_" + $launchDate + ".log"
$logPathName = "$logDirectoryPath\$logFileName"
$global:streamWriter = New-Object System.IO.StreamWriter $logPathName
#endregion
#region -----------------------------------------------------------[Functions]------------------------------------------------------------
. $loggingFunctions
. $utilsFunctions
#endregion
#region ----------------------------------------------------------[Execution]----------------------------------------------------------
Start-Log -scriptName $scriptName -scriptVersion $scriptVersion -streamWriter $global:streamWriter
cls
Write-Host "================================================================================================"
# Prerequisites
Test-InternetConnection
if($adminFlag -eq $false){
Write-Host "You have to launch this script with " -nonewline; Write-Host "local Administrator rights!" -f Red
$scriptPath = Split-Path $MyInvocation.InvocationName
$RWMC = $scriptPath + "\$scriptName.ps1"
$ArgumentList = 'Start-Process -FilePath powershell.exe -ArgumentList \"-ExecutionPolicy Bypass -File "{0}"\" -Verb Runas' -f $RWMC;
Start-Process -FilePath powershell.exe -ArgumentList $ArgumentList -Wait -NoNewWindow;
Stop-Script
}
Write-Host "================================================================================================"
#Execute action with a progressbar
Write-Progress -Activity "HelloWorld!" -status "Running..." -id 1
Write-Host HelloWorld!
#Writing informations in the log file
Write-Progress -Activity "Write informations in the log file" -status "Running..." -id 1
End-Log -streamWriter $global:streamWriter
notepad $logPathName
cls
#endregion