-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpowercli_script_template.ps1
119 lines (104 loc) · 4.02 KB
/
powercli_script_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
#requires -version 5
#requires -modules VMware.VimAutomation.Core
#requires -modules slr
<#
.SYNOPSIS
<Overview of script>
.DESCRIPTION
all scripts need to be saved in the following form for the logging function to work correct script_name.ps1 and not script-name.ps1
.PARAMETER <Parameter_Name>
<Brief description of parameter input required. Repeat this attribute if required>
.INPUTS
look at section [Define variables]
.OUTPUTS
<Outputs if any, otherwise state None - example: Log file stored in C:\Windows\Temp\<name>.log>
.NOTES
Version: 1.0
Author: Stephan Liebner
Creation Date: 01.12.2015
Purpose/Change: Initial script development
.EXAMPLE
<Example goes here. Repeat this attribute for more than one example>
#>
#---------------------------------------------------------[Initialisations]--------------------------------------------------------
#Set error action to silently continue
#$ErrorActionPreference = "SilentlyContinue"
#Set debug action to continue if you want debug messages at console
$DebugPreference="Continue"
#Determine path of script
$ScriptDir = $(Split-Path $MyInvocation.MyCommand.Definition)
#Get filename of script and use the same name for the logfile without file extension
$ScriptName = $MyInvocation.MyCommand.Name
$ScriptName = $ScriptName.Replace(".ps1","")
$ScriptFullPath = Join-Path -Path $ScriptDir -ChildPath $ScriptName
#Dot source required function libraries
#.$ScriptDir\logging_functions.ps1
#.$ScriptDir\function.ps1
#Get date today for logfile in format day-month-year_hours-minutes, e.g. 24-11-2015_19-30
$Today = get-date -format d-M-yyyy_HH-mm
#Add snap-ins or modules
#Import-Module
#Add-PSSnapin
#----------------------------------------------------------[Declarations]----------------------------------------------------------
#Script version
$ScriptVersion = "1.0"
#Define log file
$LogPath = $ScriptDir
$LogName = "$ScriptName.log"
$LogFile = Join-Path -Path $LogPath -ChildPath $LogName
#Define output file
$OutputPath=$ScriptDir
$OutputName = "$Today"+"_"+"$ScriptName.csv"
$OutputFile = Join-Path -Path $OutputPath -ChildPath $OutputName
#---------------------------------------------------------[Define variables]--------------------------------------------------------
#Define your variables here if possible
#vCenter server
$VCS = ""
#Hostname where script runs
$ScriptHostname= $env:computername
#Generate credentials for login cmdlets
#you need to run the following onetime before
#Get-Credential | Export-Clixml -Path C:\scripts\${env:USERNAME}_cred.xml
#$Credentials = Import-Clixml -Path C:\scripts\${env:USERNAME}_cred.xml
#-----------------------------------------------------------[Start Logging]------------------------------------------------------------
Log-Start -LogPath $LogPath -LogName $LogName -ScriptVersion $ScriptVersion
#-----------------------------------------------------------[Functions]------------------------------------------------------------
<#
Function <FunctionName>{
Param()
Begin{
Log-Write -LogPath $sLogFile -LineValue "<description of what is going on>..."
}
Process{
Try{
<code goes here>
}
Catch{
Log-Error -LogPath $sLogFile -ErrorDesc $Error[0] -ExitGracefully $True
Break
}
}
End{
If($?){
Log-Write -LogPath $sLogFile -LineValue "Completed Successfully."
Log-Write -LogPath $sLogFile -LineValue " "
}
}
}
#>
#-----------------------------------------------------------[Execution]------------------------------------------------------------
Log-Write -LogPath $LogFile -LineValue "Execution starts"
Log-Write -LogPath $LogFile -LineValue "Connecting to vCenter..."
Connect-VIServer -Server $VCS
#Script execution goes here
#Try
#{
#}
#Catch
#{
#Log-Error -LogPath $LogFile -ErrorDesc $Error[0] -ExitGracefully $True
#Break
#}
#-----------------------------------------------------------[Stop logging, disconnect from all vcenters and remove variables]------------------------------------------------------------
Disconnect-VIServer * -Confirm:$false
Log-Finish -LogPath $LogFile