Hi folks, new here. Had a quick look at Multiple foreach commands [SOLVED] but I’m still stuck after a few attempts with global variables and functions.
About:
This script will be run by support guys to paste in a;
a) List of usernames
b) List of token serial numbers
c) Have the script combine each line to contain both (with other items - e.g. “action,$user,$serial,item”) for an external program to parse.
…but not sure if it translates.
I can be open about the ask. I work for a company who uses 2FA tokens to log on to resources.
A recent ask is for tokens to be assigned to (non-human) bot users that requires 2FA to log on to a particular application. Human users self-serve so no issue.
The “robot” users need a PIN set and a token serial number assigned to their ID. So there are three “items” in play.
I have taken the list of user (ID) names and ran a “foreach” script to put a random six-digit PIN against each.
This is achieved by parsing a text file with a single line for each, using $variable = Get-Content -Path $path and assigning a random number (can’t remember the command but it works fine). Function:
foreach ($item in$items)
{
$PINs = Get-Random -Minimum 100000 -Maximum 999999
$output = “stuff,$item,stuff,stuff,$OTHERITEM”
}
Challenge:
How do I get a “foreach” inside the same Function to ensure the individual variable items are put together in the same output? How do I take a list from (a) user to have $OTHERITEM populate next to $item ?
#That sentence alone sounds awful!
Appreciate the comments.
Thanks