title: Scripts called from another script don't work correctly when run through task scheduler in Powershell 5.0
body: <p>I have stripped the script down so it basically does nothing but it still has open-with errors. I removed the two scripts it was calling.  I believe that I am now calling them correctly but I still have a problem with this stripped down version. I am starting it with this command which works for my other scripts: </p>
  
  <p>Powershell.exe and the argument is "-command C:\powershell\scripts\production\GetServerObjects.ps1 @Echo %errorlevel%"</p>
  
  <p>This is my first post and I am getting warnings that I'm not doing it right.  I'll work on that!</p>
  
  <p>Example of the zombie processes as seen through process monitor is here:<a href="https://i.stack.imgur.com/Vs0GM.jpg" rel="nofollow noreferrer">open- with</a></p>
  
  <p>Script is below.  It either has some errors where the server does not know how to open something or I am starting it wrong through the task scheduler.</p>
  
  <pre><code>#  Get_Server_Objects.ps1
  #  Add snapins, modules, dot source needed scripts
  
  . "C:\Powershell\Scripts\Production\invoke-Sqlcmd2.ps1"
  
  if  (-Not (Get-Module -ListAvailable -Name SQLSERVER))
          {
              Import-Module SQLServer
          }  
  
  $ResultsDir ="C:\Powershell\Results"
  $DateSuffix = "{0:MMdd}" -f (Get-Date)
  $DaysToKeep = 1      #days of results to keep.  This keeps 2 days worth.
  
  # Create a Scripter object and set the required scripting options. 
  $scrp = new-object ('Microsoft.SqlServer.Management.Smo.Scripter') ($srv)
  $scrp.Options.ExtendedProperties = $True
  
  # Make sure server list is available before proceeding.
  
  try
  {
      $Serverlist = get-content "C:\Powershell\Scripts\Production\serversshort.txt" -ea stop
  }
  catch
  {
      $output = $_.ErrorDetails
      throw $output
      Exit 1
  }
  
  #  Main Processing Loop
  foreach ($Instance in $ServerList) 
  {
      $InstDir  = $Instance.replace('\','_')
      if (!(Test-Path "$ResultsDir\$InstDir\"))                            
           {New-Item  "$ResultsDir\$InstDir\" -Type directory}
  
  # create new file names.  Automatically writes over any file of the same name.
  
          $LoginFile = "$Instdir"+'_'+"$dateSuffix" + '_CreateLogins.txt'
          $DBFile = "$Instdir"+'_'+"$dateSuffix" + '_CreateDBs.txt'
          $JobFile = "$Instdir" +'_' +"$dateSuffix" + '_Createjobs.txt'
          $ConfigFile = "$Instdir" +'_' +"$dateSuffix" + '_config.txt'
          $LinkFile = "$Instdir" +'_' +"$dateSuffix" + '_LinkedServers.txt'
          $DiskFile = "$Instdir" +'_' +"$dateSuffix" + '_DiskLayout.txt'
          $CompFile = "$Instdir" +'_' +"$dateSuffix" + '_CompLevels.txt'
  </code></pre>
  
  <p>}</p>