`…
Tool: Visual Studio Code, PowerShell Module
Version: v2022.3.0 (latest as of writing)
I have packaged a powershell script (windows form) which imports AD-Module as part of the process. When running the package, it works flawlessly but when a client tries to run it AD-module is not being installed/imported.
I have selected modules to be bundled in the package.psd1 as below:
Package = @{
Enabled = $true
Obfuscate = $false
HideConsoleWindow = $false
DotNetVersion = 'v4.6.2'
FileVersion = '1.2.0'
FileDescription = ''
ProductName = ''
ProductVersion = '1.2.0'
Copyright = ''
RequireElevation = $false
ApplicationIconPath = 'D:\Downloads\APMUserManager.ico'
PackageType = 'Console'
}
Bundle = @{
Enabled = $true
Modules = $true
# IgnoredModules = @()
}
**Console shows below errors for the client:**
Import-Module : Could not load file or assembly 'file:///C:\Users\nXXXXX\AppData\Local\Temp\236452d9-daed-4594-a0da-70a
d043f0688\ActiveDirectory\Microsoft.ActiveDirectory.Management' or one of its dependencies. The system cannot find the file specified. At line:10 char:1 + Import-Module -Name ActiveDirectory + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand
get-adobject : The 'get-adobject' command was found in the module 'ActiveDirectory', but the module could not be
loaded. For more information, run 'Import-Module ActiveDirectory'.
At line:79 char:16
+ $members = get-adobject -Credential $Credentials -Filter 'ObjectC ...
+ ~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (get-adobject:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
Exception calling "Add" with "1" argument(s): "Value cannot be null.
Parameter name: item"
At line:82 char:9
+ [void]$WorkGroupsDrop.Items.add($_.name)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentNullException
Obviously the second part of the message is due to the fact AD Module is not loading…
What am I doing wrong? Any ideas?