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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -