1
Vote

# WMI Issue Importing PSCX on Powershell v3

## description

Dear All,

I'm trying to import the PSCX module on Powershell v3 but I'm receiving the following issue(this is happening the first time when I'm openning Powershell console) If I repeat the same command the second time work without issue.

The error and the Powershell version are here:

Could you help me to understand why I'm receiving the issue?

## file attachments

wrote Jan 31, 2014 at 10:56 PM

That is an unusual location that it is attempting to load the nested module from. Can you tell me what the full path is to the pscx.psd1 file?

wrote Jan 31, 2014 at 11:52 PM

Hi, thank you for your help

the full path is:

C:\Temp\Test_Bkp\Pscx\Pscx.psd1

wrote Feb 2, 2014 at 7:34 PM

Import-Module c:\temp\test_bkp\pscx\pscx.psd1
If not, is "C:\temp\test_bkp" in your PSModulePath environment variable?

wrote Feb 2, 2014 at 8:51 PM

Yes, I'm using the full path to load the module. But currently i'm receiving that wmi issue using the last version.

Can I send you some details to identify the issue?

Something strange is this issue is hapenning the forst time so I open the powershell and I execute the import module and I'm receiving the issue if I retry the same Operation the module is loaded successful without issues.

wrote Feb 17, 2014 at 12:09 PM

Could you help me to identity the issue please?

wrote Feb 19, 2014 at 12:38 AM

Do you have another version of PSCX installed? After you import PSCX the first time, what does this command return:
(gmo pscx).path
Just want to make sure you loading the PSCX you think you are. Also, right after PSCX loads, execute:
Resolve-ErrorRecord | Out-Clipboard -width 256

wrote Feb 19, 2014 at 2:25 AM

wrote Feb 19, 2014 at 2:25 AM

Hi,

I just ran the commands these are the results (file attached)

This is the command used by the ImportModule:

Import-Module "C:\temp\Test_Bkp\Pscx\Pscx.psd1"

wrote Feb 19, 2014 at 2:27 AM

wrote Feb 19, 2014 at 2:27 AM

File attached

wrote Feb 19, 2014 at 2:29 AM

https://gbecerra.sharefile.com/d/sd3a410da0714065a

wrote Feb 20, 2014 at 4:03 PM

Something doesn't quite jive. The image clearly shows an error but Error collection is empty? Make sure you run that command "Resolve-ErrorRecord | Out-Clipboard -width 256" right after you import the pscx.psd1 file.

You might be able to work around this problem for now like so:
ipmo c:\path\to\pscx.psd1 -arg @{ModulesToImport=@{Wmi=$false}} wrote Feb 20, 2014 at 4:57 PM Hi, I just did after execute the import module and this is the error: writeErrorStream : True PSMessageDetails : Exception : System.IO.FileNotFoundException: The specified module 'C:\temp\Test_Bkp\Pscx\Modules\Wmi\Pscx.Wmi.psm1' was not loaded  because no valid module file was found in any module directory. TargetObject : C:\temp\Test_Bkp\Pscx\Modules\Wmi\Pscx.Wmi.psm1 CategoryInfo : ResourceUnavailable: (C:\temp\Test_Bk...i\Pscx.Wmi.psm1:String) [Import-Module], FileNotFoundException FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand ErrorDetails : InvocationInfo : System.Management.Automation.InvocationInfo ScriptStackTrace : at <ScriptBlock>, C:\temp\Test_Bkp\Pscx\Pscx.psm1: line 197  at <ScriptBlock>, <No file>: line 1 PipelineIterationInfo : {0, 1} MyCommand : Import-Module BoundParameters : {} UnboundArguments : {} ScriptLineNumber : 197 OffsetInLine : 13 HistoryId : 2 ScriptName : C:\temp\Test_Bkp\Pscx\Pscx.psm1 Line : Import-Module$path -DisableNameChecking

PositionMessage : At C:\temp\Test_Bkp\Pscx\Pscx.psm1:197 char:13
                    +             Import-Module $path -DisableNameChecking + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PSScriptRoot : C:\temp\Test_Bkp\Pscx PSCommandPath : C:\temp\Test_Bkp\Pscx\Pscx.psm1 InvocationName : Import-Module PipelineLength : 0 PipelinePosition : 0 ExpectingInput : False CommandOrigin : Internal DisplayScriptPosition : Exception at nesting level 0 --------------------------------------------------- Message : The specified module 'C:\temp\Test_Bkp\Pscx\Modules\Wmi\Pscx.Wmi.psm1' was not loaded because no valid module file was found in any  module directory. FileName : FusionLog : Data : {} InnerException : TargetSite : StackTrace : HelpLink : Source : HResult : -2147024894 Using the workaround is executing without showing the error, but I would like to fix to have the complete functionalities. Also I saw this when I'm importing the module without the workaround: https://gbecerra.sharefile.com/d/sa7e30316dc74fb98 wrote Feb 25, 2014 at 12:05 AM One obvious question - does this file 'C:\temp\Test_Bkp\Pscx\Modules\Wmi\Pscx.Wmi.psm1' exist? If so, can you post its contents here? wrote Feb 25, 2014 at 12:47 AM Hi, Yes the file exist. I cannot attach the complete content because there is a limitation with 1000 characters and the certificate exceed that. I will remove the certificate: Set-StrictMode -Version Latest if ($PSVersionTable.PSVersion.Major -ge 3)
{
$acceleratorsType = [psobject].Assembly.GetType('System.Management.Automation.TypeAccelerators') } else { $acceleratorsType = [Type]::GetType('System.Management.Automation.TypeAccelerators')
}

# If these accelerators have already been defined, don't override (and don't error)

function AddAccelerator($name,$type)
{
if (!$acceleratorsType::Get.ContainsKey($name))
{
$acceleratorsType::Add($name, $type) } } AddAccelerator "accelerators"$acceleratorsType

# Export nothing

Export-ModuleMember

# SIG # Begin signature block

https://gbecerra.sharefile.com/d/s6a78295822246a2b

Thanks a lot for your help :)

wrote Feb 25, 2014 at 1:33 AM

What happens if you completely strip out the signature block? I'm puzzled by this. You may need to use the workaround to disable the WMI module for now. You will only be missing two accelerators - one to convert from wmidatetime to .NET DateTime and another that converts from wmitimespan to .NET Timespan. Not a huge loss.

wrote Feb 25, 2014 at 8:43 AM

Hi,

I tried removing the complete signature block but the issue still happening. This is the error message:

Method invocation failed because [System.Management.Automation.TypeAccelerators] doesn't contain a method named 'Add'.
At C:\Temp\Test_Bkp\Pscx\Modules\Wmi\Pscx.Wmi.psm1:17 char:9
• $acceleratorsType::Add($name, $type) • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ • CategoryInfo : InvalidOperation: (:) [], ParentContainsErrorRecordException • FullyQualifiedErrorId : MethodNotFound Import-Module : The specified module 'C:\Temp\Test_Bkp\Pscx\Modules\Wmi\Pscx.Wmi.psm1' was not loaded because no valid module file was found in any module directory. At C:\Temp\Test_Bkp\Pscx\Pscx.psm1:197 char:13 • Import-Module$path -DisableNameChecking
• ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
• CategoryInfo : ResourceUnavailable: (C:\Temp\Test_Bk...i\Pscx.Wmi.psm1:String) [Import-Module], FileNotFoundException
• FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Do you know why this could be happen?

I will keep using the workaround for now, thanks a lot for your help :)