title: Passing Command to Mongo Shell with --eval returns undefined
body: <p>I'm attempting to write a script to deploy mongodb for customers using Powershell (whatever version comes with Server2016). I can install as a service and get it up and running just fine, but I want to also add authentication. Specifically I want to add an admin user and the database user. </p>
  
  <p>Initially I create the mongod service with this powershell function:</p>
  
  <pre><code>function createMongoService([string] $mongoDbConfigPath, [string] $serviceName, [string] $storePath, [string] $authCmd)
  {
      $mongodexe = "$mongoInstallPath\bin\mongod.exe"
      Write-Host "Activating Mongod as a service '$serviceName'"
      "auth cmd = $authCmd"
      &amp; $mongodexe --config "$mongoDbConfigPath" --install --serviceName "$serviceName" --serviceDisplayName "Storfirst MongoDB" --port 27710 --dbpath "$storePath\db" $authCmd
      if ($LASTEXITCODE -ne 0)
      {
          throw "Failed to start service"
      }
  }
  </code></pre>
  
  <p>In the initial case, $authCmd is "". Looking at the logs, I can confirm that the service is being started WITHOUT authentication.</p>
  
  <blockquote>
    <p>2018-06-13T16:00:26.600-0700 I CONTROL  [initandlisten] ** WARNING:
    Access control is not enabled for the database.
    2018-06-13T16:00:26.600-0700 I CONTROL  [initandlisten] **<br>
    Read and write access to data and configuration is unrestricted.</p>
  </blockquote>
  
  <p>Then I go to create the mongo user with this function:</p>
  
  <pre><code>function createAdminUser( [string] $mongoInstallPath, [string] $mongoAdminName, [string] $mongoAdminPass)
  {
      Write-Host "Creating admin user"
      $createAdminCmd = `
          "db.createUser( `
              { `
                  user: `"$mongoAdminName`", 
                  pwd: `"$mongoAdminPass`", 
                  roles: [ { role: `"userAdminAnyDatabase`", db: `"admin`" } ] `
              } `
          );"
      "$createAdminCmd"
      &amp; "$mongoInstallPath\bin\mongo.exe" admin --port 27710  --eval "$createAdminCmd"
  
      if ($LASTEXITCODE -ne 0)
      {
          throw "Failed to create admin user"
      }
  }
  </code></pre>
  
  <p>But this fails with the following error printed to screen (nothing about it is logged in the mongodb log). mongoAdminName is equal to administrator in this run, but it gives me the same results with the equivalent admin name if I use something else.</p>
  
  <blockquote>
    <p>MongoDB shell version v3.4.15-49-g4ef027f98d connecting to:
    mongodb://127.0.0.1:27710/admin MongoDB server version:
    3.4.15-49-g4ef027f98d 2018-06-13T16:10:00.125-0700 E QUERY    [thread1] ReferenceError: administrator is not defined : @(shell
    eval):1:17</p>
  </blockquote>
  
  <p>This happens even if I enter the expected command by hand in powershell.
  I use a similar command to create users on our custom mongodb docker container and have no problems with that, but I need a non-container solution in this case.</p>
  
  <p>The plan is, once I've created the admin user, reexecute the createMongoService, this time with authCmd equal to "--auth", then use the admin user to create the database user with standard authentication practices.
  My questions are "whats going on here?!?" and "how do I fix this?"</p>