Search code examples
powershellpowershell-3.0sqlps

How to diagnose this exception from Invoke-Sqlcmd?


I'm running the following command (smallest reproducible example I could come up with):

Invoke-Sqlcmd "select * from sys.databases"  | %{
    Invoke-Sqlcmd "select 1"     
}

I'm getting the following error:

Invoke-Sqlcmd : Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "pipeline.resources" was correctly embedded or linked into assembly "System.Management.Automation" at compile time, or that all the satellite assemblies required are loadable and fully signed. At line:1 char:1 + Invoke-Sqlcmd "select * from sys.databases" | %{ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidResult: (:) [Invoke-Sqlcmd], MissingManifestResourceException + FullyQualifiedErrorId : ExecutionFailed,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand

Tired this:

  • both with ISE and command line
  • both elevated ("run as administrator") and not
  • against SQL 2012 and SQL 2008
  • from a Windows 8 and from Server 2008

In all cases the result is the same.

Why and how to diagnose?


Solution

  • I've also noticed issues using invoke-sqlcmd to chain together invoke-sqlcmd commands via pipeline. A workaround which seems to address issue, save the output of first command to variable then pipe output to next invoke-sqlcmd call.

    $databases = Invoke-Sqlcmd "select * from sys.databases"  
    $databases | % { Invoke-Sqlcmd "select 1" }