What I want to do: I have a string i.e "peter" and want to output the 1st character (p) in a variable. Then the first 2 charachters (pe) etc. until the end of the string (peter). At the end I would have 5 different variables. Could anyone help me out how to do that in powershell ?
What I have tried is:
$Inputstring ="peter"
$CharArray =$InputString.ToCharArray()
$CharArray
but this gave me
p
e
t
e
r
This here looks good:
$TstString = "peter"
$CharArray = $TstString.ToCharArray()
$CharArray[0]
$CharArray[0] + $CharArray[1]
$CharArray[0] + $CharArray[1]+ $CharArray[2]
$CharArray[0] + $CharArray[1]+ $CharArray[2]+ $CharArray[3]
$CharArray[0] + $CharArray[1]+ $CharArray[2]+ $CharArray[3] + $CharArray[4]
p
pe
pet
pete
peter
I want to use that for checking ActiveDirectory for existing email address and if exist like p@dom.com; pe@dom.com ....