I have a simple Powershell Module, Test.psm1
#requires -Version 5.1
#region Using Statements
using namespace System.Web
#endregion
class Test {
Test()
{
[String] $UserPrincipalName = "john.smith@nowhere.com"
[String] $filter = "userPrincipalName eq '{0}'" -f $UserPrincipalName
[String] $select = "id, userPrincipalName"
$queryString = [HttpUtility]::ParseQueryString([String]::Empty)
$queryString.Add('$filter', $filter)
$queryString.Add('$select', $select)
[String] $baseUri = "https://graph.microsoft.com/v1.0/users"
[UriBuilder] $queryObject = $baseUri
$queryObject.Query = $queryString.ToString()
[String] $uri = $queryObject.Uri.OriginalString
Write-Host($uri)
}
}
and a script that invokes the class constructor above
#requires -Version 5.1
#region Using Statements
using module .\Test.psd1
#endregion
class Program {
static [void] Main() {
[Test]::new()
}
}
[Program]::Main()
The file Test.psd1 contains the property for RequiredAssemblies
RequiredAssemblies = 'System.Web'
My pspack.config.psd1 files contents are
@{
Root = ".\TestHttp.ps1";
OutputPath = ".\TestHttp";
Bundle = @{
Enabled = $true;
Modules = $true;
NestedModules = $true;
RequiredAssemblies = $true;
}
Package = @{
Enabled = $true
Obfuscate = $true
}
}
After I run the
Merge-Script -ConfigFile .\pspack.config.psd1 -Verbose
and run the resulting EXE file I get the following error
Import-Module : File C:\temp\Test.psm1 cannot be loaded. The file C:\temp\Test.psm1 is not digitally signed. You
cannot run this script on the current system. For more information about running scripts and setting execution policy,
see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
+ CategoryInfo : SecurityError: (:) [Import-Module], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess,Microsoft.PowerShell.Commands.ImportModuleCommand
This seems to suggest that the script bundling is really not happening if it is still looking on the disk for Test.psm1 file. What do I need to change to make this work?