You can pass them on the command line:
myscriptname "server1" "server2" "server3"
Then remove the
Get-Content
line and replace the
foreach
loop reading from the file by
foreach ($computername in $args)
{
# Do the work here
}
If the cmdlet is called from another cmdlet where the list is stored in an array you can execute it as:
& myscriptname @ServerList
or
Invoke-Expression "myscriptname $ServerList"