0

I'm having a frustrating issue with our deployment script that is currently working on Server 2008 R2 and I can't get to start on Server 2012 due to issues with PS not recognizing our custom modules we copy over and import.

Error:

Import-Module : The specified module 'LoggingModule' was not loaded because no valid module file was found in any module directory.

I have checked the PSModulePath environment variable and modified it manually to include our set path and I have even set our script to call the module files directly. Here's the section of relevant code:

try {
. ".\CopyModules.ps1" -debug:$debug
$moduledir = ($env:USERPROFILE + "\Documents\WindowsPowerShell\Modules")

Import-Module $moduledir\LoggingModule\LoggingModule.psm1 -DisableNameChecking -Args $debug

InitializeLogging -LogPathArg "$LocalBuildDirectory\build-log-$(get-date -f yyyy-MM-dd).txt"

if (-not (Get-Module WindowsModule)) {
    Import-Module $moduledir\WindowsModule\WindowsModule.psm1 -DisableNameChecking
}

if (-not (Get-Module WebRequestModule)) {
    Import-Module $moduledir\WebRequestModule\WebRequestModule.psm1 -DisableNameChecking
}
}
catch {
Write-Error "Error importing modules to local system. Application cannot continue without modules being installed correctly"
Write-Error $_
exit
}

CopyModules.ps1:

Param([switch]$debug)

function Get-WorkingDirectory
{
$dir = [System.String]::Empty;

if($hostinvocation -ne $null)
{
    $dir = Split-Path $hostinvocation.MyCommand.path
}
else
{
    $dir = Split-Path $script:MyInvocation.MyCommand.Path
}

return $dir
}

#  "Include" these, with ClientSetup.ps1 first - it defines the globals 
# and functions needed by the other files.

$BuildModulesPath = "$(Get-WorkingDirectory)\Modules\*"
$PSModulePath = (New-Item -ItemType Directory -Path ($env:USERPROFILE + "\Documents\WindowsPowerShell\Modules") -Force -ErrorAction Stop)# | Out-Null

try {
Copy-Item $BuildModulesPath -Destination $PSModulePath -Recurse -Force
if ($debug)
{
    Write-Host "DEBUG: Modules copied from: $BuildModulesPath"
    Write-Host "DEBUG: Modules copied to: $PSModulePath"
}
}
catch {
Write-Error "Could not copy modules to module directory"
throw
}

CopyModules does not fail and I see the files in their directory.

The script is being called through this command:

powershell.exe -ExecutionPolicy Bypass \\deployserver.com\Staging\Builds\Scripts\StartBuild.ps1 -build Server2012 -debug

As a side note this does not occur when I add -Version 2 to the script command. However, I can't run the deployment in Version 2 due to issues with the ActiveDirectory module not loading on Server 2012 under Version 2 mode (it required Version 3 or higher).

This situation also does occur when running the above command with -Version 3 added.

HopelessN00b
  • 53,795
  • 33
  • 135
  • 209
The_Gribbler
  • 45
  • 1
  • 4

1 Answers1

0

Well, the issue was with the LoggingModule.psm1 file itself. There was a segment of code that created an error that I was missing due to the PowerShell window and it's buffer-size (cut off at top). The module file was corrected and the remaining modules were loaded.

The_Gribbler
  • 45
  • 1
  • 4