Page 1 of 1

Error - Generate Query PowerShell Script

Posted: Tue Jun 19, 2018 7:52 am
by Nillth
Product, version and build: PowerShell Studio 2018 v5.5.152
32 or 64 bit version of product: 64 bit
Operating system: Windows 10 (1803)
32 or 64 bit OS: 64 bit

*** Please add details and screenshots as needed below. ***

In the Object Browser panel, i have selected a database I configured in Primal SQL.
from there I select a table, right click "Generate Query PowerShell Script..."
Sapien-Generate_Query_PowerShell_Script.PNG
Sapien-Generate_Query_PowerShell_Script.PNG (30.88 KiB) Viewed 1643 times

Select a name,
Save
When the script opens and I attempt to run it I get the following error


>> Running (Get-Query_Postgre_public_Users.ps1) Script...
>> Platform: V5 64Bit (STA)
>> Analyzing Script (Results in Debug pane)...
ERROR: Add-Type : Cannot add type. The assembly 'Npgsql, Version=2.0.13.91, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7' could not be found.
Get-Query_Postgre_public_Users.ps1 (9, 1): ERROR: At Line: 9 char: 1
ERROR: + Add-Type -AssemblyName 'Npgsql, Version=2.0.13.91, Culture=neutral, P ...
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : ObjectNotFound: (Npgsql, Version...d8b90d52f46fda7:String) [Add-Type], Exception
ERROR: + FullyQualifiedErrorId : ASSEMBLY_NOT_FOUND,Microsoft.PowerShell.Commands.AddTypeCommand
ERROR:
ERROR: Add-Type : Cannot add type. One or more required assemblies are missing.
Get-Query_Postgre_public_Users.ps1 (9, 1): ERROR: At Line: 9 char: 1
ERROR: + Add-Type -AssemblyName 'Npgsql, Version=2.0.13.91, Culture=neutral, P ...
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : InvalidData: (:) [Add-Type], InvalidOperationException
ERROR: + FullyQualifiedErrorId : ASSEMBLY_LOAD_ERRORS,Microsoft.PowerShell.Commands.AddTypeCommand
ERROR:
ERROR: New-Object : Cannot find type [Npgsql.NpgsqlCommand]: verify that the assembly containing this type is loaded.
Get-Query_Postgre_public_Users.ps1 (15, 12): ERROR: At Line: 15 char: 12
ERROR: + $command = New-Object Npgsql.NpgsqlCommand ($QueryString, $Connection ...
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
ERROR: + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
ERROR:
ERROR: New-Object : Cannot find type [Npgsql.NpgsqlDataAdapter]: verify that the assembly containing this type is loaded.
Get-Query_Postgre_public_Users.ps1 (16, 12): ERROR: At Line: 16 char: 12
ERROR: + $adapter = New-Object Npgsql.NpgsqlDataAdapter ($command)
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
ERROR: + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
ERROR:
ERROR: You cannot call a method on a null-valued expression.
Get-Query_Postgre_public_Users.ps1 (20, 1): ERROR: At Line: 20 char: 1
ERROR: + [void]$adapter.Fill($dataset)
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : InvalidOperation: (:) [], RuntimeException
ERROR: + FullyQualifiedErrorId : InvokeMethodOnNull
ERROR:

*** PowerShell Script finished. ***
>> Execution time: < 1 second
>> Script Ended

Re: Error - Generate Query PowerShell Script

Posted: Tue Jun 19, 2018 8:10 am
by davidc
The script requires the Postgre .NET provider to run. You can find the dll in PowerShell Studio's installation directory:

C:\Program Files\SAPIEN Technologies, Inc\PowerShell Studio 2018\Npgsql.dll

I recommend add it to the Global Assembly Cache so that PowerShell can locate it.