0

I am creating a powershell script and need some help. I need to create an array and attach it to a string.

I have 3 required parameters

$printername
$start
$end

So if user enters the following for the 3 parameters: hp, 1, 5 I need to attach the following to a string called $printers $printers = hp1 hp2 hp3 hp4 hp5.

If they entered 1000 for the last parameter this would have to go through hp1000

How can I create this array.

1 Answer 1

3

Seems simple enough.

function Make-PrinterString
{
   Param (
    [string]$Prefix,
    [int]$Start,
    [int]$End
    )

   [string]($start..$end | foreach {"$Prefix$_"})
}

Make-PrinterString HP 1 5

HP1 HP2 HP3 HP4 HP5
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.