powershell - Capture multiple variables -
i have powershell script allows me enter in details users 1 @ time can used variables later on. @ present script calls each input , saves variable, repeated 10 times.
[system.reflection.assembly]::loadwithpartialname('microsoft.visualbasic') | out-null $nameone = [microsoft.visualbasic.interaction]::inputbox("enter username") $firstname,$surname = $nameone -split("\.") $nametwo = [microsoft.visualbasic.interaction]::inputbox("enter username") $firstname,$surname = $nametwo -split("\.")
is there way shorten script both allow usernames input , stored move on next part of script when inputbox has no data input?
thanks tom
use while
loop:
$users = while(($username = [microsoft.visualbasic.interaction]::inputbox("enter username")).trim() -ne "") { $firstname,$surname = $username -split '\.' new-object psobject -property @{ firstname = $firstname surname = $surname username = $username } }
when user inputs nothing or whitespace, loop exit, otherwise it'll create new "user object" end in $users
array
Comments
Post a Comment