From dd9650afb05cb267e6e393efa3c3ffdb2fa4ce2f Mon Sep 17 00:00:00 2001 From: Gary Blake Date: Fri, 9 Oct 2020 14:35:09 +0100 Subject: [PATCH 1/3] Added Useful Script Functions --- PowerVCF.psd1 | 8 +++++- PowerVCF.psm1 | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/PowerVCF.psd1 b/PowerVCF.psd1 index 7d79907cd..7adf98903 100644 --- a/PowerVCF.psd1 +++ b/PowerVCF.psd1 @@ -21,7 +21,7 @@ ModuleVersion = '2.2.0' GUID = '08e28c56-f231-4a2c-8906-dee337cf99b9' # Author of this module -Author = 'Brian O Connell' +Author = 'Brian O Connell & Gary Blake' # Description of the functionality provided by this module 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.' # Minimum version of the Windows PowerShell host required by this module # PowerShellHostVersion = '' +# Modules that must be imported into the global environment prior to importing this module +# RequiredModules = @('') + +# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess +# NestedModules = @() + # 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. FunctionsToExport = '*' diff --git a/PowerVCF.psm1 b/PowerVCF.psm1 index adedd01d9..a6afecb9f 100644 --- a/PowerVCF.psm1 +++ b/PowerVCF.psm1 @@ -5003,3 +5003,70 @@ Function validateJsonInput } ######### End Utility Functions (not exported) ########## + + + +######### Start Useful Script Functions ########## + +Function Start-SetupLogFile +{ + $filetimeStamp = Get-Date -Format "MM-dd-yyyy_hh_mm_ss" + $Global:logFile = $PSScriptRoot+'\logs\'+$scriptName+'-'+$filetimeStamp+'.log' + $logFolder = $PSScriptRoot+'\logs' + $logFolderExists = Test-Path $logFolder + if (!$logFolderExists) { + New-Item -ItemType Directory -Path $logFolder | Out-Null + } + New-Item -type File -Path $logFile | Out-Null + $logContent = '['+$filetimeStamp+'] Beginning of Log File' + Add-Content -Path $logFile $logContent | Out-Null +} +Export-ModuleMember -Function Start-SetupLogFile + +Function Write-LogMessage +{ + Param ( + [Parameter(Mandatory=$true)] + [String]$message, + [Parameter(Mandatory=$false)] + [String]$colour, + [Parameter(Mandatory=$false)] + [string]$skipNewLine + ) + + If (!$colour) { + $colour = "Cyan" + } + + $timeStamp = Get-Date -Format "MM-dd-yyyy_HH:mm:ss" + + Write-Host -NoNewline -ForegroundColor White " [$timeStamp]" + If ($skipNewLine) { + Write-Host -NoNewline -ForegroundColor $colour " $message" + } + else { + Write-Host -ForegroundColor $colour " $message" + } + $logContent = '['+$timeStamp+'] '+$message + Add-Content -path $logFile $logContent +} +Export-ModuleMember -Function Write-LogMessage + + +Function Debug-CatchWriter +{ + Param ( + [Parameter(Mandatory=$true)] + [PSObject]$object + ) + + $lineNumber = $object.InvocationInfo.ScriptLineNumber + $lineText = $object.InvocationInfo.Line.trim() + $errorMessage = $object.Exception.Message + Write-LogMessage -message " Error at Script Line $lineNumber" -colour Red + Write-LogMessage -message " Relevant Command: $lineText" -colour Red + Write-LogMessage -message " Error Message: $errorMessage" -colour Red +} +Export-ModuleMember -Function Debug-CatchWriter + +######### End Useful Script Functions ########## From 9b7da38cd3e90190bb2d073cec3d9c87eac916f4 Mon Sep 17 00:00:00 2001 From: Gary Blake Date: Tue, 27 Oct 2020 09:19:14 +0000 Subject: [PATCH 2/3] Start-SetupLogFile - Added Path Input --- PowerVCF.psm1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PowerVCF.psm1 b/PowerVCF.psm1 index a6afecb9f..ec677b8dc 100644 --- a/PowerVCF.psm1 +++ b/PowerVCF.psm1 @@ -5008,11 +5008,11 @@ Function validateJsonInput ######### Start Useful Script Functions ########## -Function Start-SetupLogFile +Function Start-SetupLogFile ($path) { $filetimeStamp = Get-Date -Format "MM-dd-yyyy_hh_mm_ss" - $Global:logFile = $PSScriptRoot+'\logs\'+$scriptName+'-'+$filetimeStamp+'.log' - $logFolder = $PSScriptRoot+'\logs' + $Global:logFile = $path+'\logs\'+$scriptName+'-'+$filetimeStamp+'.log' + $logFolder = $path+'\logs' $logFolderExists = Test-Path $logFolder if (!$logFolderExists) { New-Item -ItemType Directory -Path $logFolder | Out-Null From 8e1da16a5e77f3a2774cd20fb83617e5b608d5a9 Mon Sep 17 00:00:00 2001 From: Gary Blake Date: Fri, 6 Nov 2020 17:23:12 +0000 Subject: [PATCH 3/3] Update PowerVCF.psm1 --- PowerVCF.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PowerVCF.psm1 b/PowerVCF.psm1 index ec677b8dc..55099389d 100644 --- a/PowerVCF.psm1 +++ b/PowerVCF.psm1 @@ -3145,7 +3145,7 @@ Function Start-CloudBuilderSDDCValidation [ValidateNotNullOrEmpty()] [String]$json, [Parameter (Mandatory=$false)] - [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")] + [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")] [String]$validation ) @@ -5008,7 +5008,7 @@ Function validateJsonInput ######### Start Useful Script Functions ########## -Function Start-SetupLogFile ($path) +Function Start-SetupLogFile ($path, $scriptName) { $filetimeStamp = Get-Date -Format "MM-dd-yyyy_hh_mm_ss" $Global:logFile = $path+'\logs\'+$scriptName+'-'+$filetimeStamp+'.log'