title: Powershell script not running from batch file
body: <p>I've written the following script to add a user to MS Live:</p>
  
  <pre><code>$pass = Get-Content D:\PSScripts\pass.txt | ConvertTo-SecureString
  $cred = New-Object System.Management.Automation.PSCredential "user@domain.com", $pass
  Connect-MsolService -Credential $cred
  New-MsolUser -userprincipalname test@domain.com -Displayname "Johny Tester2"
  </code></pre>
  
  <p>I can copy and paste the commands to PowerShell line by line and successfully create a new user, but I can't figure out how to run them all from command line. </p>
  
  <p>I saved the above 4 lines in a file at D:\PSScripts\script2.ps1</p>
  
  <p>I created a file: D:\PSScripts\runall.bat with the following content:</p>
  
  <p>powershell.exe "&amp; 'D:\PSScripts\script2.ps1'"</p>
  
  <p>(I also tried without the &amp; sign, without the quotes, without the 'exe', with -command switch)</p>
  
  <p>It looks like it goes through the first two lines and then it throws and error on 'Connect-MsolService' and 'New-MsolUser':</p>
  
  <p><em>The term 'Connect-MsolService' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.</em></p>
  
  <p>I need to be able to execute those commands from another program and running a bat file is my best option. Please help.</p>
  
  <p>Running on Win Server 2008 R2, PowerShell Version 2.0</p>