I seek assistance in figuring out how to capture new dynamic variables and add them to an array.
Below is a sample code that creates the variables.
foreach ($user in $users) {
New-Variable -Name "$($user)_pwString" -Value ([System.Web.Security.Membership]::GeneratePassword(10,4)) -Force
}
This will create several variables as such:
$Guest01_pwString
$Guest02_pwString
$Guest03_pwString
How could capture each of the variables it creates and add them into an array.
What I thought would have worked:
$secureStrings = @()
foreach ($user in $users) {
$secureStrings += (New-Variable -Name "$($user)_pwString" -Value ([System.Web.Security.Membership]::GeneratePassword(10,4)) -Force)
}