I have a function that I am trying to make unto a module to use in my daily sripts. I want it to work kind of like (writeI -host "hello" -fore red -back black" where it has flags and values. I have already named is with psm1 and put it in the pwershell\modules\Make-Tbox folder.
How can I get this to work as I am caliing it from the MAIN example below? I would like the flags to be otional so it can function like regular cmdlets Thank you very much
##################### Make-Tbox Module ################################
# Functions
function Make-Tbox {
param($Tbox, $Txt, $locx) # $Tbox =line to create, $txt =text to use, $locx =location indent
switch ($Tbox){
"top" {$tChar1 ="╔═"; $tChar2 ="═╗"}
"cntr" {$tChar1 ="║ "; $tChar2 =" ║"
for($i = 0; $i -lt ($BoxWidth - $Txt.length) /2 ; $i++) {$string = $string + " "}
$string = $string + $Txt
for($i = $i; $i -lt ($BoxWidth - $Txt.length); $i++) {$string = $string + " "}
}
"blank" {$tChar1 ="║ "; $tChar2 =" ║"
for($i = 0; $i -lt $BoxWidth; $i++){
$string = $string + " " }
}
"mid" {$tChar1 ="╠═"; $tChar2 ="═╣"}
"btm" {$tChar1 ="╚═"; $tChar2 ="═╝"}
"leftT" {$tChar1 ="║ "; $tChar2 =" ║"
for($i = 0; $i -lt ($locx); $i++) {$string = $string + " "}
$string = $string + $Txt
for ($i = 0; $i -lt (($BoxWidth - $Txt.length)-$locx); $i++) {$string = $string + "}
}
}
if ($Tbox -ne "cntr" -and $Tbox -ne "leftT" -and $Tbox -ne "blank") {for($i = 0; $i -lt $BoxWidth; $i++) {$string = $string + "=" }
}
write-host $tChar1 -Fore $BoxFgColor -nonewline -Back $BoxBgColor
write-host $string -Fore $BoxFgColor -nonewline -Back $BoxBgColor
write-host $tChar2 -Fore $BoxFgColor -Back $BoxBgColor
}
###########################################Every Day Scripts calling module make-Tbox #################
# MAIN
# Color choices are Black DarkBlue DarkGreen DarkCyan DarkRed DarkMagenta DarkYellow Gray DarkGray Blue Green Cyan Red Magenta Yellow White
#Box description Parameters: Width of the box, Foreground color, Background color
$BoxWidth = 80
$BoxFgColor = "white"
$BoxBgColor = "black"
clear-host
#Create the box line by line and items by calling desired flag
Make-Tbox top
Make-Tbox cntr "My Title" green
Make-Tbox mid
Make-Tbox blank
Make-Tbox cntr "1. Option 1" magenta
Make-Tbox cntr "2. Option 2" blue
Make-Tbox cntr "3. Option 3" cyan
Make-Tbox leftT "4. Option4" yellow 20
Make-Tbox leftT "5. Exit" green 20
Make-Tbox blank
Make-Tbox btm
#Ask the user for thir Choice
Write-Host "`nPlease make a choice (1-5): " -fore red -back Black -NoNewline
$UsrChoice = Read-Host
###########################################################################################
# Decision Process
switch ($UsrChoice) {
"1" {"Change settings"; break}
"2" {"Static settings"; break}
"3" {"option 3"; break}
"4" {"Near the end"; break}
"5" {break}
default {"Please choose only from the displayed list"; break}
#
Example Image https://i.stack.imgur.com/8P9oh.png
my example code shows what I tried