Package Modules is not packaging modules

I’m fairly new to PowerShell Pro Tools and Visual Studio so my guess is that I’m doing something wrong - just don’t know what.
I started a PowerShell Script project that relies on the SQLServer module. It contains the database password and I wanted to distribute outside the team, so I had bundle, package as exe, obfuscate, and package modules enabled. Runs fine on machines with SQLServer installed, and complains that it can’t find the module where it’s not.
If it helps, I do not have the analyzer installed and I get an error when I try to debug (Value does not fall within the expected range). However the build process runs without errors.
I’m running Visual Studio 2019 and PowerShell Pro Tools 5.4.4.

@cbricecmb -

Welcome!

Can you put some more information about your script? I’m specifically looking for the Import-Module call you are making to include the SqlServer module.

PoshTools will continue on it’s merry way if it can’t find the module but should output into the Output window when it fails to find a module during bundling so there might be more information there.

It’s just a real simple Import-Module -Name SQLServer.
Here’s the build output:
------ Build started: Project: VDIUserEventQuery, Configuration: Debug Any CPU ------
Checking license
OutputPath is C:\Users\a5357a\source\repos\VDIUserEventQuery\bin\Debug
Bundling VDIUserEventQuery.ps1
Packaging C:\Users\a5357a\AppData\Local\Temp\VDIUserEventQuery.ps1
Checking dotnet version.
3.1.201

	Creating package project.
	Using .NET Framework version: net472
	  Restore completed in 133 ms for C:\Users\a5357a\AppData\Local\Temp\190c7d9f11ce4ebfbde86d0a3e513d2b\VDIUserEventQuery.csproj.

	Packaging C:\Users\a5357a\AppData\Local\Temp\VDIUserEventQuery.ps1 -> C:\Users\a5357a\source\repos\VDIUserEventQuery\bin\Debug\\VDIUserEventQuery.exe
	Microsoft (R) Build Engine version 16.5.0+d4cbfca49 for .NET Core

Copyright © Microsoft Corporation. All rights reserved.

Restore completed in 42.38 ms for C:\Users\a5357a\AppData\Local\Temp\190c7d9f11ce4ebfbde86d0a3e513d2b\VDIUserEventQuery.csproj.
VDIUserEventQuery -> C:\Users\a5357a\source\repos\VDIUserEventQuery\bin\Debug\VDIUserEventQuery.exe

Build succeeded.
0 Warning(s)
0 Error(s)

Time Elapsed 00:00:01.63

	Obfuscating C:\Users\a5357a\source\repos\VDIUserEventQuery\bin\Debug\\VDIUserEventQuery.exe
	Loading project C:\Users\a5357a\AppData\Local\Temp\tmp3B2.tmp...Processing assembly: VDIUserEventQuery, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

Loading assemblies…Extra framework folders: Done.
hiding strings…
Renaming: fields…parameters…properties…events…methods…types…Done.
Saving assemblies…Done.
Writing log file…Done.
Completed, 0.44 secs.

	Obfuscation complete: C:\Users\a5357a\source\repos\VDIUserEventQuery\bin\Debug\

========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

I’m seeing this with the latest as well.

So I’m NOT crazy?

Now I’m going crazy. I thought it didn’t work but it appears to. Can you make sure that you have both packaging and bundling enabled? Here are the settings I’m using.

image

image

The script is just:

Import-Module SqlServer

The resulting exe is about 25mb.

Here is me running the exe on a separate machine that doesn’t have the SqlServer module installed.

image

Tried sending screen shots but being new I’m limited.

The only difference between you and me was Obfuscate. I disabled that and rebuilt. Executable is 9k.

Can you let me know a little more about this?

If it helps, I do not have the analyzer installed and I get an error when I try to debug (Value does not fall within the expected range). However the build process runs without errors.

Do you see an error when calling Import-Module SqlServer on this machine?

The reason I ask is that internally, the packager will import the module to determine information about it so it can package it correctly.

What’s a little weird is that the packager should throw an exception if it can’t import the module.

No errors importing the module.

PS C:\Users\a5357a> Import-Module -name SqlServer -Verbose

VERBOSE: Loading module from path ‘C:\Program Files\WindowsPowerShell\Modules\SqlServer\21.1.18221\SqlServer.psd1’.

VERBOSE: Populating RepositorySourceLocation property for module SqlServer.

VERBOSE: Loading module from path ‘C:\Program Files\WindowsPowerShell\Modules\SqlServer\21.1.18221\sqlnotebook.psm1’.

VERBOSE: Exporting function ‘Invoke-SqlNotebook’.

VERBOSE: Importing function ‘Invoke-SqlNotebook’.

VERBOSE: Loading module from path ‘C:\Program Files\WindowsPowerShell\Modules\SqlServer\21.1.18221\SqlServer.psm1’.

VERBOSE: Exporting function ‘Invoke-SqlNotebook’.

VERBOSE: Exporting function ‘SQLSERVER:’.

VERBOSE: Exporting cmdlet ‘Add-SqlColumnEncryptionKeyValue’.

VERBOSE: Exporting cmdlet ‘Complete-SqlColumnMasterKeyRotation’.

VERBOSE: Exporting cmdlet ‘Get-SqlColumnEncryptionKey’.

VERBOSE: Exporting cmdlet ‘Get-SqlColumnMasterKey’.

VERBOSE: Exporting cmdlet ‘Add-SqlAzureAuthenticationContext’.

VERBOSE: Exporting cmdlet ‘New-SqlColumnEncryptionKeyEncryptedValue’.

VERBOSE: Exporting cmdlet ‘New-SqlColumnEncryptionSettings’.

VERBOSE: Exporting cmdlet ‘New-SqlColumnMasterKeySettings’.

VERBOSE: Exporting cmdlet ‘New-SqlCspColumnMasterKeySettings’.

VERBOSE: Exporting cmdlet ‘New-SqlCngColumnMasterKeySettings’.

VERBOSE: Exporting cmdlet ‘Remove-SqlColumnEncryptionKey’.

VERBOSE: Exporting cmdlet ‘Remove-SqlColumnEncryptionKeyValue’.

VERBOSE: Exporting cmdlet ‘Remove-SqlColumnMasterKey’.

VERBOSE: Exporting cmdlet ‘Invoke-SqlColumnMasterKeyRotation’.

VERBOSE: Exporting cmdlet ‘Set-SqlColumnEncryption’.

VERBOSE: Exporting cmdlet ‘New-SqlAzureKeyVaultColumnMasterKeySettings’.

VERBOSE: Exporting cmdlet ‘New-SqlColumnEncryptionKey’.

VERBOSE: Exporting cmdlet ‘New-SqlColumnMasterKey’.

VERBOSE: Exporting cmdlet ‘New-SqlCertificateStoreColumnMasterKeySettings’.

VERBOSE: Exporting cmdlet ‘Backup-SqlDatabase’.

VERBOSE: Exporting cmdlet ‘Get-SqlBackupHistory’.

VERBOSE: Exporting cmdlet ‘Restore-SqlDatabase’.

VERBOSE: Exporting cmdlet ‘Get-SqlSensitivityClassification’.

VERBOSE: Exporting cmdlet ‘Get-SqlSensitivityRecommendations’.

VERBOSE: Exporting cmdlet ‘Remove-SqlSensitivityClassification’.

VERBOSE: Exporting cmdlet ‘Set-SqlSensitivityClassification’.

VERBOSE: Exporting cmdlet ‘Get-SqlErrorLog’.

VERBOSE: Exporting cmdlet ‘Set-SqlErrorLog’.

VERBOSE: Exporting cmdlet ‘Add-SqlAvailabilityDatabase’.

VERBOSE: Exporting cmdlet ‘Add-SqlAvailabilityGroupListenerStaticIp’.

VERBOSE: Exporting cmdlet ‘Disable-SqlAlwaysOn’.

VERBOSE: Exporting cmdlet ‘Enable-SqlAlwaysOn’.

VERBOSE: Exporting cmdlet ‘Switch-SqlAvailabilityGroup’.

VERBOSE: Exporting cmdlet ‘Revoke-SqlAvailabilityGroupCreateAnyDatabase’.

VERBOSE: Exporting cmdlet ‘Set-SqlAvailabilityReplicaRoleToSecondary’.

VERBOSE: Exporting cmdlet ‘Grant-SqlAvailabilityGroupCreateAnyDatabase’.

VERBOSE: Exporting cmdlet ‘Join-SqlAvailabilityGroup’.

VERBOSE: Exporting cmdlet ‘New-SqlAvailabilityGroup’.

VERBOSE: Exporting cmdlet ‘New-SqlAvailabilityGroupListener’.

VERBOSE: Exporting cmdlet ‘New-SqlAvailabilityReplica’.

VERBOSE: Exporting cmdlet ‘New-SqlHADREndpoint’.

VERBOSE: Exporting cmdlet ‘Remove-SqlAvailabilityGroup’.

VERBOSE: Exporting cmdlet ‘Remove-SqlAvailabilityDatabase’.

VERBOSE: Exporting cmdlet ‘Remove-SqlAvailabilityReplica’.

VERBOSE: Exporting cmdlet ‘Resume-SqlAvailabilityDatabase’.

VERBOSE: Exporting cmdlet ‘Set-SqlAvailabilityGroup’.

VERBOSE: Exporting cmdlet ‘Set-SqlAvailabilityGroupListener’.

VERBOSE: Exporting cmdlet ‘Set-SqlAvailabilityReplica’.

VERBOSE: Exporting cmdlet ‘Set-SqlHADREndpoint’.

VERBOSE: Exporting cmdlet ‘Suspend-SqlAvailabilityDatabase’.

VERBOSE: Exporting cmdlet ‘Test-SqlAvailabilityGroup’.

VERBOSE: Exporting cmdlet ‘Test-SqlAvailabilityReplica’.

VERBOSE: Exporting cmdlet ‘Test-SqlDatabaseReplicaState’.

VERBOSE: Exporting cmdlet ‘Add-SqlFirewallRule’.

VERBOSE: Exporting cmdlet ‘Get-SqlDatabase’.

VERBOSE: Exporting cmdlet ‘Remove-SqlFirewallRule’.

VERBOSE: Exporting cmdlet ‘Set-SqlAuthenticationMode’.

VERBOSE: Exporting cmdlet ‘Set-SqlNetworkConfiguration’.

VERBOSE: Exporting cmdlet ‘Start-SqlInstance’.

VERBOSE: Exporting cmdlet ‘Stop-SqlInstance’.

VERBOSE: Exporting cmdlet ‘Invoke-PolicyEvaluation’.

VERBOSE: Exporting cmdlet ‘Get-SqlAgent’.

VERBOSE: Exporting cmdlet ‘Get-SqlAgentJob’.

VERBOSE: Exporting cmdlet ‘Get-SqlAgentJobHistory’.

VERBOSE: Exporting cmdlet ‘Get-SqlAgentJobStep’.

VERBOSE: Exporting cmdlet ‘Get-SqlAgentJobSchedule’.

VERBOSE: Exporting cmdlet ‘Get-SqlAgentSchedule’.

VERBOSE: Exporting cmdlet ‘Save-SqlMigrationReport’.

VERBOSE: Exporting cmdlet ‘Read-SqlTableData’.

VERBOSE: Exporting cmdlet ‘Read-SqlViewData’.

VERBOSE: Exporting cmdlet ‘Write-SqlTableData’.

VERBOSE: Exporting cmdlet ‘Invoke-Sqlcmd’.

VERBOSE: Exporting cmdlet ‘Add-SqlLogin’.

VERBOSE: Exporting cmdlet ‘Get-SqlLogin’.

VERBOSE: Exporting cmdlet ‘Remove-SqlLogin’.

VERBOSE: Exporting cmdlet ‘Get-SqlSmartAdmin’.

VERBOSE: Exporting cmdlet ‘Set-SqlSmartAdmin’.

VERBOSE: Exporting cmdlet ‘Test-SqlSmartAdmin’.

VERBOSE: Exporting cmdlet ‘Get-SqlCredential’.

VERBOSE: Exporting cmdlet ‘Get-SqlInstance’.

VERBOSE: Exporting cmdlet ‘New-SqlBackupEncryptionOption’.

VERBOSE: Exporting cmdlet ‘New-SqlCredential’.

VERBOSE: Exporting cmdlet ‘Remove-SqlCredential’.

VERBOSE: Exporting cmdlet ‘Set-SqlCredential’.

VERBOSE: Exporting cmdlet ‘Export-SqlVulnerabilityAssessmentBaselineSet’.

VERBOSE: Exporting cmdlet ‘Export-SqlVulnerabilityAssessmentScan’.

VERBOSE: Exporting cmdlet ‘Import-SqlVulnerabilityAssessmentBaselineSet’.

VERBOSE: Exporting cmdlet ‘Invoke-SqlVulnerabilityAssessmentScan’.

VERBOSE: Exporting cmdlet ‘New-SqlVulnerabilityAssessmentBaselineSet’.

VERBOSE: Exporting cmdlet ‘New-SqlVulnerabilityAssessmentBaseline’.

VERBOSE: Exporting cmdlet ‘Read-SqlXEvent’.

VERBOSE: Exporting cmdlet ‘Convert-UrnToPath’.

VERBOSE: Exporting cmdlet ‘ConvertTo-EncodedSqlName’.

VERBOSE: Exporting cmdlet ‘ConvertFrom-EncodedSqlName’.

VERBOSE: Exporting cmdlet ‘Add-RoleMember’.

VERBOSE: Exporting cmdlet ‘Backup-ASDatabase’.

VERBOSE: Exporting cmdlet ‘Invoke-ASCmd’.

VERBOSE: Exporting cmdlet ‘Invoke-ProcessCube’.

VERBOSE: Exporting cmdlet ‘Invoke-ProcessDimension’.

VERBOSE: Exporting cmdlet ‘Invoke-ProcessASDatabase’.

VERBOSE: Exporting cmdlet ‘Invoke-ProcessTable’.

VERBOSE: Exporting cmdlet ‘Invoke-ProcessPartition’.

VERBOSE: Exporting cmdlet ‘Remove-RoleMember’.

VERBOSE: Exporting cmdlet ‘Restore-ASDatabase’.

VERBOSE: Exporting cmdlet ‘New-RestoreFolder’.

VERBOSE: Exporting cmdlet ‘New-RestoreLocation’.

VERBOSE: Exporting cmdlet ‘Merge-Partition’.

VERBOSE: Exporting cmdlet ‘Get-SqlAssessmentItem’.

VERBOSE: Exporting cmdlet ‘Invoke-SqlAssessment’.

VERBOSE: Exporting alias ‘Encode-SqlName’.

VERBOSE: Exporting alias ‘Decode-SqlName’.

VERBOSE: Importing cmdlet ‘Add-RoleMember’.

VERBOSE: Importing cmdlet ‘Add-SqlAvailabilityDatabase’.

VERBOSE: Importing cmdlet ‘Add-SqlAvailabilityGroupListenerStaticIp’.

VERBOSE: Importing cmdlet ‘Add-SqlAzureAuthenticationContext’.

VERBOSE: Importing cmdlet ‘Add-SqlColumnEncryptionKeyValue’.

VERBOSE: Importing cmdlet ‘Add-SqlFirewallRule’.

VERBOSE: Importing cmdlet ‘Add-SqlLogin’.

VERBOSE: Importing cmdlet ‘Backup-ASDatabase’.

VERBOSE: Importing cmdlet ‘Backup-SqlDatabase’.

VERBOSE: Importing cmdlet ‘Complete-SqlColumnMasterKeyRotation’.

VERBOSE: Importing cmdlet ‘Convert-UrnToPath’.

VERBOSE: Importing cmdlet ‘ConvertFrom-EncodedSqlName’.

VERBOSE: Importing cmdlet ‘ConvertTo-EncodedSqlName’.

VERBOSE: Importing cmdlet ‘Disable-SqlAlwaysOn’.

VERBOSE: Importing cmdlet ‘Enable-SqlAlwaysOn’.

VERBOSE: Importing cmdlet ‘Export-SqlVulnerabilityAssessmentBaselineSet’.

VERBOSE: Importing cmdlet ‘Export-SqlVulnerabilityAssessmentScan’.

VERBOSE: Importing cmdlet ‘Get-SqlAgent’.

VERBOSE: Importing cmdlet ‘Get-SqlAgentJob’.

VERBOSE: Importing cmdlet ‘Get-SqlAgentJobHistory’.

VERBOSE: Importing cmdlet ‘Get-SqlAgentJobSchedule’.

VERBOSE: Importing cmdlet ‘Get-SqlAgentJobStep’.

VERBOSE: Importing cmdlet ‘Get-SqlAgentSchedule’.

VERBOSE: Importing cmdlet ‘Get-SqlAssessmentItem’.

VERBOSE: Importing cmdlet ‘Get-SqlBackupHistory’.

VERBOSE: Importing cmdlet ‘Get-SqlColumnEncryptionKey’.

VERBOSE: Importing cmdlet ‘Get-SqlColumnMasterKey’.

VERBOSE: Importing cmdlet ‘Get-SqlCredential’.

VERBOSE: Importing cmdlet ‘Get-SqlDatabase’.

VERBOSE: Importing cmdlet ‘Get-SqlErrorLog’.

VERBOSE: Importing cmdlet ‘Get-SqlInstance’.

VERBOSE: Importing cmdlet ‘Get-SqlLogin’.

VERBOSE: Importing cmdlet ‘Get-SqlSensitivityClassification’.

VERBOSE: Importing cmdlet ‘Get-SqlSensitivityRecommendations’.

VERBOSE: Importing cmdlet ‘Get-SqlSmartAdmin’.

VERBOSE: Importing cmdlet ‘Grant-SqlAvailabilityGroupCreateAnyDatabase’.

VERBOSE: Importing cmdlet ‘Import-SqlVulnerabilityAssessmentBaselineSet’.

VERBOSE: Importing cmdlet ‘Invoke-ASCmd’.

VERBOSE: Importing cmdlet ‘Invoke-PolicyEvaluation’.

VERBOSE: Importing cmdlet ‘Invoke-ProcessASDatabase’.

VERBOSE: Importing cmdlet ‘Invoke-ProcessCube’.

VERBOSE: Importing cmdlet ‘Invoke-ProcessDimension’.

VERBOSE: Importing cmdlet ‘Invoke-ProcessPartition’.

VERBOSE: Importing cmdlet ‘Invoke-ProcessTable’.

VERBOSE: Importing cmdlet ‘Invoke-SqlAssessment’.

VERBOSE: Importing cmdlet ‘Invoke-Sqlcmd’.

VERBOSE: Importing cmdlet ‘Invoke-SqlColumnMasterKeyRotation’.

VERBOSE: Importing cmdlet ‘Invoke-SqlVulnerabilityAssessmentScan’.

VERBOSE: Importing cmdlet ‘Join-SqlAvailabilityGroup’.

VERBOSE: Importing cmdlet ‘Merge-Partition’.

VERBOSE: Importing cmdlet ‘New-RestoreFolder’.

VERBOSE: Importing cmdlet ‘New-RestoreLocation’.

VERBOSE: Importing cmdlet ‘New-SqlAvailabilityGroup’.

VERBOSE: Importing cmdlet ‘New-SqlAvailabilityGroupListener’.

VERBOSE: Importing cmdlet ‘New-SqlAvailabilityReplica’.

VERBOSE: Importing cmdlet ‘New-SqlAzureKeyVaultColumnMasterKeySettings’.

VERBOSE: Importing cmdlet ‘New-SqlBackupEncryptionOption’.

VERBOSE: Importing cmdlet ‘New-SqlCertificateStoreColumnMasterKeySettings’.

VERBOSE: Importing cmdlet ‘New-SqlCngColumnMasterKeySettings’.

VERBOSE: Importing cmdlet ‘New-SqlColumnEncryptionKey’.

VERBOSE: Importing cmdlet ‘New-SqlColumnEncryptionKeyEncryptedValue’.

VERBOSE: Importing cmdlet ‘New-SqlColumnEncryptionSettings’.

VERBOSE: Importing cmdlet ‘New-SqlColumnMasterKey’.

VERBOSE: Importing cmdlet ‘New-SqlColumnMasterKeySettings’.

VERBOSE: Importing cmdlet ‘New-SqlCredential’.

VERBOSE: Importing cmdlet ‘New-SqlCspColumnMasterKeySettings’.

VERBOSE: Importing cmdlet ‘New-SqlHADREndpoint’.

VERBOSE: Importing cmdlet ‘New-SqlVulnerabilityAssessmentBaseline’.

VERBOSE: Importing cmdlet ‘New-SqlVulnerabilityAssessmentBaselineSet’.

VERBOSE: Importing cmdlet ‘Read-SqlTableData’.

VERBOSE: Importing cmdlet ‘Read-SqlViewData’.

VERBOSE: Importing cmdlet ‘Read-SqlXEvent’.

VERBOSE: Importing cmdlet ‘Remove-RoleMember’.

VERBOSE: Importing cmdlet ‘Remove-SqlAvailabilityDatabase’.

VERBOSE: Importing cmdlet ‘Remove-SqlAvailabilityGroup’.

VERBOSE: Importing cmdlet ‘Remove-SqlAvailabilityReplica’.

VERBOSE: Importing cmdlet ‘Remove-SqlColumnEncryptionKey’.

VERBOSE: Importing cmdlet ‘Remove-SqlColumnEncryptionKeyValue’.

VERBOSE: Importing cmdlet ‘Remove-SqlColumnMasterKey’.

VERBOSE: Importing cmdlet ‘Remove-SqlCredential’.

VERBOSE: Importing cmdlet ‘Remove-SqlFirewallRule’.

VERBOSE: Importing cmdlet ‘Remove-SqlLogin’.

VERBOSE: Importing cmdlet ‘Remove-SqlSensitivityClassification’.

VERBOSE: Importing cmdlet ‘Restore-ASDatabase’.

VERBOSE: Importing cmdlet ‘Restore-SqlDatabase’.

VERBOSE: Importing cmdlet ‘Resume-SqlAvailabilityDatabase’.

VERBOSE: Importing cmdlet ‘Revoke-SqlAvailabilityGroupCreateAnyDatabase’.

VERBOSE: Importing cmdlet ‘Save-SqlMigrationReport’.

VERBOSE: Importing cmdlet ‘Set-SqlAuthenticationMode’.

VERBOSE: Importing cmdlet ‘Set-SqlAvailabilityGroup’.

VERBOSE: Importing cmdlet ‘Set-SqlAvailabilityGroupListener’.

VERBOSE: Importing cmdlet ‘Set-SqlAvailabilityReplica’.

VERBOSE: Importing cmdlet ‘Set-SqlAvailabilityReplicaRoleToSecondary’.

VERBOSE: Importing cmdlet ‘Set-SqlColumnEncryption’.

VERBOSE: Importing cmdlet ‘Set-SqlCredential’.

VERBOSE: Importing cmdlet ‘Set-SqlErrorLog’.

VERBOSE: Importing cmdlet ‘Set-SqlHADREndpoint’.

VERBOSE: Importing cmdlet ‘Set-SqlNetworkConfiguration’.

VERBOSE: Importing cmdlet ‘Set-SqlSensitivityClassification’.

VERBOSE: Importing cmdlet ‘Set-SqlSmartAdmin’.

VERBOSE: Importing cmdlet ‘Start-SqlInstance’.

VERBOSE: Importing cmdlet ‘Stop-SqlInstance’.

VERBOSE: Importing cmdlet ‘Suspend-SqlAvailabilityDatabase’.

VERBOSE: Importing cmdlet ‘Switch-SqlAvailabilityGroup’.

VERBOSE: Importing cmdlet ‘Test-SqlAvailabilityGroup’.

VERBOSE: Importing cmdlet ‘Test-SqlAvailabilityReplica’.

VERBOSE: Importing cmdlet ‘Test-SqlDatabaseReplicaState’.

VERBOSE: Importing cmdlet ‘Test-SqlSmartAdmin’.

VERBOSE: Importing cmdlet ‘Write-SqlTableData’.

VERBOSE: Importing function ‘Invoke-SqlNotebook’.

VERBOSE: Importing function ‘SQLSERVER:’.

VERBOSE: Importing alias ‘Decode-SqlName’.

VERBOSE: Importing alias ‘Encode-SqlName’.

Ok. Thanks. I’m going to push a new release of PoshTools tomorrow to resolve some issues but I’ll get some additional logging in there so that we can narrow down why the packager is skipping this module on your machine.

If it helps I get the same results trying to package PowerCLI.

Adam – I’ve got good news and bad news.

The good news is that I can get the module packaging to work in the Visual Studio Code editor.

The bad news is the Invoke-Sqlcmd command needs to load the Microsoft.SqlServer.BatchParser dll and can’t find it. Seems like the temp folder where the module is extracted is not in the search path.

Invoke-Sqlcmd : Could not load file or assembly 'Microsoft.SqlServer.BatchParser, Version=15.100.0.0, Culture=neutral,

PublicKeyToken=89845dcd8080cc91’ or one of its dependencies. The system cannot find the file specified.

At line:13 char:1

  • Invoke-Sqlcmd -ServerInstance ‘sbc-esdsql1’ -Database 'VMWViewEventDB …

  • 
    
  • CategoryInfo : NotSpecified: (:slight_smile: [Invoke-Sqlcmd], FileNotFoundException

  • FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.SqlServer.Management.PowerShell.GetScriptComma

nd

Here’s the build output error from Visual Studio w/ version 5.4.6 :
Found module import ‘Import-Module -Name SqlServer’ at 88
Error while import module: System.Management.Automation.PSSecurityException: File C:\Program Files\WindowsPowerShell\Modules\SqlServer\21.1.18221\sqlnotebook.psm1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170. —> System.UnauthorizedAccessException: File C:\Program Files\WindowsPowerShell\Modules\SqlServer\21.1.18221\sqlnotebook.psm1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.

My execution policy is set to unrestricted.

image

What’s the execution policy set to on your machine? Just pop open a PowerShell.exe and run Get-ExecutionPolicy. The packaging runs in MSBuild so it’s currently not using the ‘Enable Unrestricted Execution Policy’ setting. That’s for the debugger in VS.

Unrestricted.

Hmmmm. Ok. No idea why that’s happening…I guess I’ll have to see what I can do there to work around that.

Also, I’m seeing the same thing with the VS Code package that you are. I’ll let you know what I find there. Looking into that now.

It looks like the SQLServer module requires x64. The default architecture of packaged apps is x86. I adjusted my package.psd1 like this:

@{
        Root = 'c:\Users\adamr\Source\Repos\PowerShellFormProject2\Script1.ps1'
        OutputPath = 'c:\Users\adamr\Source\Repos\PowerShellFormProject2\out'
        Package = @{
            Enabled = $true
            Obfuscate = $false
            HideConsoleWindow = $false
            DotNetVersion = 'v4.7.2'
            FileVersion = '1.0.0'
            FileDescription = ''
            ProductName = ''
            ProductVersion = ''
            Copyright = ''
            RequireElevation = $false
            ApplicationIconPath = ''
            PackageType = 'Console'
            Platform = 'x64' 
        }
        Bundle = @{
            Enabled = $true
            Modules = $true
            # IgnoredModules = @()
        }
    }
    

My script is just:

Import-Module SqlServer
Invoke-SqlCmd -Query 'Select * FRom table'

Success! Thank you!

FYI - In Visual Studio I set the Platform to x64 in the Project Properties. Getting the same build error.