Skip to content

Commit

Permalink
Change Footer text and amend formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
vreguibar committed Aug 8, 2024
1 parent b6fc392 commit b3f23cd
Show file tree
Hide file tree
Showing 53 changed files with 993 additions and 733 deletions.
8 changes: 4 additions & 4 deletions Enums/Enum.Constants.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
# Standard header used on each function on the Begin section
Header = @'
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
┃ EguibarIT module
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ EguibarIT module ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
Date: {0}
Starting: {1}
Expand All @@ -63,7 +63,7 @@
# Standard footer used on each function on the Begin section
Footer = @'
Function {0} finished {1}"
Function {0} finished {1}"
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
Expand Down
34 changes: 24 additions & 10 deletions Private/Get-ADCSTemplate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ Function Get-ADCSTemplate {
.NOTES
https://www.powershellgallery.com/packages/ADCSTemplate/1.0.1.0/Content/ADCSTemplate.psm1
#>
[CmdletBinding(ConfirmImpact = 'Low')]
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Low')]
[OutputType([Microsoft.ActiveDirectory.Management.ADEntity])]

param(
[Parameter(Mandatory = $false,
ValueFromPipeline = $true,
Expand All @@ -43,6 +45,7 @@ Function Get-ADCSTemplate {
[string]
$Server
)

Begin {
$txt = ($constants.Header -f
(Get-Date).ToShortDateString(),
Expand All @@ -54,11 +57,11 @@ Function Get-ADCSTemplate {
##############################
# Module imports



##############################
# Variables Definition

[hashtable]$Splat = [hashtable]::New([StringComparer]::OrdinalIgnoreCase)

if (-not $Server) {
$Server = (Get-ADDomainController -Discover -ForceDiscover -Writable).HostName[0]
}
Expand All @@ -69,24 +72,35 @@ Function Get-ADCSTemplate {
$LDAPFilter = '(objectClass=pKICertificateTemplate)'
} #end If
} #end Begin

Process {
$ConfigNC = $((Get-ADRootDSE -Server $Server).configurationNamingContext)

$TemplatePath = ('CN=Certificate Templates,CN=Public Key Services,CN=Services,{0}' -f $ConfigNC)
$TemplatePath = 'CN=Certificate Templates,CN=Public Key Services,CN=Services,{0}' -f $Variables.configurationNamingContext

$result = Get-ADObject -SearchScope Subtree -SearchBase $TemplatePath -LDAPFilter $LDAPFilter -Properties * -Server $Server
$Splat = @{
SearchScope = 'Subtree'
SearchBase = $TemplatePath
LDAPFilter = $LDAPFilter
Properties = '*'
Server = $Server
}
$result = Get-ADObject @Splat

# Output verbose information
foreach ($item in $result) {
Write-Verbose -Message ('Template Name: {0}' -f $item.Name)
Write-Verbose -Message ('Created: {0}, Modified: {1}' -f $item.Created, $item.Modified)
} #end ForEach

} #end Process

End {
Write-Verbose -Message "Function $($MyInvocation.InvocationName) finished."
Write-Verbose -Message ''
Write-Verbose -Message '-------------------------------------------------------------------------------'
Write-Verbose -Message ''
$txt = ($Constants.Footer -f $MyInvocation.InvocationName,
'getting Cert Template.'
)
Write-Verbose -Message $txt

return $result
} #end End

} #end Function
8 changes: 4 additions & 4 deletions Private/Get-AdObjectType.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@
} # End Process Section

End {
Write-Verbose -Message "Function $($MyInvocation.InvocationName) finished getting AD object type."
Write-Verbose -Message ''
Write-Verbose -Message '-------------------------------------------------------------------------------'
Write-Verbose -Message ''
$txt = ($Constants.Footer -f $MyInvocation.InvocationName,
'getting AD object type.'
)
Write-Verbose -Message $txt

if ($null -ne $ReturnValue) {
Write-Output $ReturnValue
Expand Down
12 changes: 8 additions & 4 deletions Private/Get-CurrentErrorToDisplay.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function Get-CurrentErrorToDisplay {
#>
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Low')]
[OutputType([System.String])]

Param (
[Parameter(Mandatory = $false,
ValueFromPipeline = $true,
Expand Down Expand Up @@ -143,10 +144,13 @@ function Get-CurrentErrorToDisplay {
$result = $OutputError.ToString()
Write-Verbose -Message 'Cleaning the $error variable'
$error.Clear()
Write-Verbose -Message "Function $($MyInvocation.InvocationName) finished."
Write-Verbose -Message ''
Write-Verbose -Message '-------------------------------------------------------------------------------'
Write-Verbose -Message ''

$txt = ($Constants.Footer -f $MyInvocation.InvocationName,
'getting Displaying current error.'
)
Write-Verbose -Message $txt

return $result
} # End END section

} # End Function
133 changes: 69 additions & 64 deletions Private/Get-IniContent.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function Get-IniContent {
<#
<#
.Synopsis
Gets the content of an INI file
Expand Down Expand Up @@ -49,69 +49,74 @@ function Get-IniContent {
Out-IniFile
#>

[CmdletBinding(ConfirmImpact = 'Medium')]
[OutputType([System.Collections.Hashtable])]
Param(
[ValidateNotNullOrEmpty()]
[Parameter(ValueFromPipeline = $true, HelpMessage = 'Path and Filename to the ini file to be read', Mandatory = $true)]
[string]$FilePath
)
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Low')]
[OutputType([System.Collections.Hashtable])]

Begin {
$txt = ($constants.Header -f
Param(
[ValidateNotNullOrEmpty()]
[Parameter(ValueFromPipeline = $true, HelpMessage = 'Path and Filename to the ini file to be read', Mandatory = $true)]
[string]$FilePath
)

Begin {
$txt = ($constants.Header -f
(Get-Date).ToShortDateString(),
$MyInvocation.Mycommand,
$MyInvocation.Mycommand,
(Get-FunctionDisplay $PsBoundParameters -Verbose:$False)
)
Write-Verbose -Message $txt

##############################
# Variables Definition
} #end Begin

Process {
Write-Verbose -Message "$($myInvocation.MyCommand.Name):: Processing file: $PSBoundParameters['FilePath']"

Try {
$ini = @{}
switch -regex -file $PSBoundParameters['FilePath'] {
'^\[(.+)\]$' { # Section
$section = $matches[1]
$ini[$section] = @{}
$CommentCount = 0
}
'^(;.*)$' { # Comment
if (!($section)) {
$section = 'No-Section'
$ini[$section] = @{}
}
$value = $matches[1]
$CommentCount = $CommentCount + 1
$name = 'Comment' + $CommentCount
$ini[$section][$name] = $value
}
'(.+?)\s*=\s*(.*)' { # Key
if (!($section)) {
$section = 'No-Section'
$ini[$section] = @{}
}
$name, $value = $matches[1..2]
$ini[$section][$name] = $value
}
} #end Switch
} catch {
Write-Error -Message "An error occurred while processing the file: $_"
throw
} #end Try-Catch
Write-Verbose -Message "$($myInvocation.MyCommand.Name):: Finished Processing file: $PSBoundParameters['FilePath']"

} # End Process

End {
Write-Verbose -Message "Function $($MyInvocation.InvocationName) finished reading content from $PSBoundParameters['FilePath'] file."
Write-Verbose -Message ''
Write-Verbose -Message '-------------------------------------------------------------------------------'
Write-Verbose -Message ''
Return $ini
} #end End
}
)
Write-Verbose -Message $txt

##############################
# Variables Definition
} #end Begin

Process {
Write-Verbose -Message "$($myInvocation.MyCommand.Name):: Processing file: $PSBoundParameters['FilePath']"

Try {
$ini = @{}
switch -regex -file $PSBoundParameters['FilePath'] {
'^\[(.+)\]$' {
# Section
$section = $matches[1]
$ini[$section] = @{}
$CommentCount = 0
}
'^(;.*)$' {
# Comment
if (!($section)) {
$section = 'No-Section'
$ini[$section] = @{}
}
$value = $matches[1]
$CommentCount = $CommentCount + 1
$name = 'Comment' + $CommentCount
$ini[$section][$name] = $value
}
'(.+?)\s*=\s*(.*)' {
# Key
if (!($section)) {
$section = 'No-Section'
$ini[$section] = @{}
}
$name, $value = $matches[1..2]
$ini[$section][$name] = $value
}
} #end Switch
} catch {
Write-Error -Message "An error occurred while processing the file: $_"
throw
} #end Try-Catch
Write-Verbose -Message "$($myInvocation.MyCommand.Name):: Finished Processing file: $PSBoundParameters['FilePath']"

} # End Process

End {
$txt = ($Constants.Footer -f $MyInvocation.InvocationName,
('reading content from {0} file.' -f $PSBoundParameters['FilePath'])
)
Write-Verbose -Message $txt

Return $ini
} #end End
} #end Function
54 changes: 41 additions & 13 deletions Private/Get-RandomHex.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,60 @@ Function Get-RandomHex {
Eguibar Information Technology S.L.
http://www.eguibarit.com
#>
[CmdletBinding(SupportsShouldProcess = $False)]
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Low')]
[OutputType([string])]

param (
[parameter(Mandatory = $true,
HelpMessage = 'Specify the length of the hexadecimal string.')]
[ValidateRange(1, [int]::MaxValue)]
[int]$Length
)

try {
Begin {
$txt = ($constants.Header -f
(Get-Date).ToShortDateString(),
$MyInvocation.Mycommand,
(Get-FunctionDisplay $PsBoundParameters -Verbose:$False)
)
Write-Verbose -Message $txt

##############################
# Module imports

##############################
# Variables Definition

# Generating random hexadecimal string
$Hex = '0123456789ABCDEF'
[string]$Return = $null

for ($i = 1; $i -le $Length; $i++) {
$Return += $Hex.Substring((Get-Random -Minimum 0 -Maximum 16), 1)
}
} #end Begin

# Displaying verbose output
Write-Verbose "Generated random hexadecimal string: $Return"
Process {
try {
for ($i = 1; $i -le $Length; $i++) {
$Return += $Hex.Substring((Get-Random -Minimum 0 -Maximum 16), 1)
} #end For

# Displaying verbose output
Write-Verbose -Message ('Generated random hexadecimal string: {0}' -f $Return)

} catch {
# Handling exceptions
###Get-CurrentErrorToDisplay -CurrentError $error[0]
throw
} #end Try
} #end Process

End {
$txt = ($Constants.Footer -f $MyInvocation.InvocationName,
'generating random hexadecimal string.'
)
Write-Verbose -Message $txt

# Returning the generated string
$Return
}
catch {
# Handling exceptions
###Get-CurrentErrorToDisplay -CurrentError $error[0]
throw
} #end Try
} #end End

} #end Function
11 changes: 6 additions & 5 deletions Private/Initialize-ModuleVariable.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,10 @@
} #end Process

End {
Write-Verbose -Message "Function $($MyInvocation.InvocationName) finished initializing Variables."
Write-Verbose -Message ''
Write-Verbose -Message '-------------------------------------------------------------------------------'
Write-Verbose -Message ''
$txt = ($Constants.Footer -f $MyInvocation.InvocationName,
'initializing Variables.'
)
Write-Verbose -Message $txt
} #end End
}

} #end Function
13 changes: 8 additions & 5 deletions Private/New-Template.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Function New-Template {
http://www.eguibarit.com
#>
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Low')]
[OutputType([void])]

Param(
[Parameter(Mandatory = $true,
ValueFromPipeline = $true,
Expand Down Expand Up @@ -129,9 +131,10 @@ Function New-Template {
} # End PROCESS section

End {
Write-Verbose -Message "Function $($MyInvocation.InvocationName) adding new PKI template."
Write-Verbose -Message ''
Write-Verbose -Message '--------------------------------------------------------------------------------'
Write-Verbose -Message ''
} # End PROCESS section
$txt = ($Constants.Footer -f $MyInvocation.InvocationName,
'adding new PKI template.'
)
Write-Verbose -Message $txt
} #end End section

} # End Function New-Template
Loading

0 comments on commit b3f23cd

Please sign in to comment.