Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.

Commit e7f3492

Browse files
Merge pull request #113 from PowerVCF/dev-gjb-410-testModules
Useful Functions for Scripting
2 parents 37a5054 + 8e1da16 commit e7f3492

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed

PowerVCF.psd1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ ModuleVersion = '2.2.0'
2121
GUID = '08e28c56-f231-4a2c-8906-dee337cf99b9'
2222

2323
# Author of this module
24-
Author = 'Brian O Connell'
24+
Author = 'Brian O Connell & Gary Blake'
2525

2626
# Description of the functionality provided by this module
2727
Description = 'PowerShell Module for the VMware Cloud Foundation 4.x API.'
@@ -35,6 +35,12 @@ Description = 'PowerShell Module for the VMware Cloud Foundation 4.x API.'
3535
# Minimum version of the Windows PowerShell host required by this module
3636
# PowerShellHostVersion = ''
3737

38+
# Modules that must be imported into the global environment prior to importing this module
39+
# RequiredModules = @('')
40+
41+
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
42+
# NestedModules = @()
43+
3844
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
3945
FunctionsToExport = '*'
4046

PowerVCF.psm1

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3145,7 +3145,7 @@ Function Start-CloudBuilderSDDCValidation
31453145
[ValidateNotNullOrEmpty()]
31463146
[String]$json,
31473147
[Parameter (Mandatory=$false)]
3148-
[ValidateSet("JSON_SPEC_VALIDATION","LICENSE_KEY_VALIDATION","TIME_SYNC_VALIDATION","NETWORK_IP_POOLS_VALIDATION","NETWORK_CONFIG_VALIDATION","MANAGEMENT_NETWORKS_VALIDATION","ESXI_VERSION_VALIDATION","ESXI_HOST_READINESS_VALIDATION","PASSWORDS_VALIDATION","HOST_IP_DNS_VALIDATION","IP_RESOLUTION_VALIDATION","CLOUDBUILDER_READY_VALIDATION","VSAN_AVAILABILITY_VALIDATION","NSXT_NETWORKS_VALIDATION")]
3148+
[ValidateSet("JSON_SPEC_VALIDATION","LICENSE_KEY_VALIDATION","TIME_SYNC_VALIDATION","NETWORK_IP_POOLS_VALIDATION","NETWORK_CONFIG_VALIDATION","MANAGEMENT_NETWORKS_VALIDATION","ESXI_VERSION_VALIDATION","ESXI_HOST_READINESS_VALIDATION","PASSWORDS_VALIDATION","HOST_IP_DNS_VALIDATION","CLOUDBUILDER_READY_VALIDATION","VSAN_AVAILABILITY_VALIDATION","NSXT_NETWORKS_VALIDATION","AVN_NETWORKS_VALIDATION")]
31493149
[String]$validation
31503150
)
31513151

@@ -5003,3 +5003,70 @@ Function validateJsonInput
50035003
}
50045004

50055005
######### End Utility Functions (not exported) ##########
5006+
5007+
5008+
5009+
######### Start Useful Script Functions ##########
5010+
5011+
Function Start-SetupLogFile ($path, $scriptName)
5012+
{
5013+
$filetimeStamp = Get-Date -Format "MM-dd-yyyy_hh_mm_ss"
5014+
$Global:logFile = $path+'\logs\'+$scriptName+'-'+$filetimeStamp+'.log'
5015+
$logFolder = $path+'\logs'
5016+
$logFolderExists = Test-Path $logFolder
5017+
if (!$logFolderExists) {
5018+
New-Item -ItemType Directory -Path $logFolder | Out-Null
5019+
}
5020+
New-Item -type File -Path $logFile | Out-Null
5021+
$logContent = '['+$filetimeStamp+'] Beginning of Log File'
5022+
Add-Content -Path $logFile $logContent | Out-Null
5023+
}
5024+
Export-ModuleMember -Function Start-SetupLogFile
5025+
5026+
Function Write-LogMessage
5027+
{
5028+
Param (
5029+
[Parameter(Mandatory=$true)]
5030+
[String]$message,
5031+
[Parameter(Mandatory=$false)]
5032+
[String]$colour,
5033+
[Parameter(Mandatory=$false)]
5034+
[string]$skipNewLine
5035+
)
5036+
5037+
If (!$colour) {
5038+
$colour = "Cyan"
5039+
}
5040+
5041+
$timeStamp = Get-Date -Format "MM-dd-yyyy_HH:mm:ss"
5042+
5043+
Write-Host -NoNewline -ForegroundColor White " [$timeStamp]"
5044+
If ($skipNewLine) {
5045+
Write-Host -NoNewline -ForegroundColor $colour " $message"
5046+
}
5047+
else {
5048+
Write-Host -ForegroundColor $colour " $message"
5049+
}
5050+
$logContent = '['+$timeStamp+'] '+$message
5051+
Add-Content -path $logFile $logContent
5052+
}
5053+
Export-ModuleMember -Function Write-LogMessage
5054+
5055+
5056+
Function Debug-CatchWriter
5057+
{
5058+
Param (
5059+
[Parameter(Mandatory=$true)]
5060+
[PSObject]$object
5061+
)
5062+
5063+
$lineNumber = $object.InvocationInfo.ScriptLineNumber
5064+
$lineText = $object.InvocationInfo.Line.trim()
5065+
$errorMessage = $object.Exception.Message
5066+
Write-LogMessage -message " Error at Script Line $lineNumber" -colour Red
5067+
Write-LogMessage -message " Relevant Command: $lineText" -colour Red
5068+
Write-LogMessage -message " Error Message: $errorMessage" -colour Red
5069+
}
5070+
Export-ModuleMember -Function Debug-CatchWriter
5071+
5072+
######### End Useful Script Functions ##########

0 commit comments

Comments
 (0)