Wildcard Matching
I am writing a function in an attempt to enumerate through the environment variables and find the least common denominator when returning wildcards.Right below is the output that I recieve and I honestly have no idea where these digits are coming from. It's def the indexed positions, but I did not instruct it to happen. This some weird behavior of the array list?
I think since it it processing it backwards its is also grabbing environment variables matching "?" and resolving to that, but any error handling ive tried to avoid that has been unsuccessful
0
1
2
3
4
5
6
7
8
${env:userdomai?}
${env:userdoma??}
${env:userdom???}
${env:userdo????}
${env:userd?????}
${env:user??????}
${env:use???????}
${env:us????????}
${env:u?????????}
function wildCard-Replace {
param (
[string]$string
)
$modifiedString = $string
$options = New-Object System.Collections.ArrayList
$yup = New-Object System.Collections.ArrayList
# Iterate through each character in the string in reverse order
for ($i = $string.Length - 1; $i -ge 0; $i--) {
# Replace the character with a question mark
$modifiedString = $modifiedString.Substring(0, $i) + "?" + $modifiedString.Substring($i + 1)
$ModStringValue = (get-item "env:$modifiedString").value
$constant = ('${'+"env:$string}").Value
$validated = ('${'+"env:$modifiedString}")
if (($modifiedString -match "[^?]") -and ($ModStringValue -like "*$constant*")){
$yup.Add($validated) #| Out-Null
}
}
return $yup
}