How do I write a script that opens an iTerm2 window and runs a command?
Try this:

tell application "iTerm2"
    set newWindow to (create window with default profile)
    tell current session of newWindow
        write text "echo it works!"
    end tell
end tell


The write command, when not using without newline, executes the write text command because of the default added newline after the "text to send". Thus the window stays open after the command completes, ready for additional use.



From the iTerm AppleScript Dictionary:


  write v : Send text as though it was typed.
  
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;write specifier : The session to send to
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[contents of file file] : Filename to send the contents of
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[text text] : Text to send
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[newline boolean] : If newline should be added to end of text (default: yes)