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:
https://gbecerra.sharefile.com/download.aspx?id=s0692091ff8e49549

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

Thanks in advance,

file attachments

comments

r_keith_hill wrote Jan 31 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?

gbecerra1982 wrote Jan 31 at 11:52 PM

Hi, thank you for your help

the full path is:

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

r_keith_hill wrote Feb 2 at 7:34 PM

Are you loading the module using the full path e.g.:
Import-Module c:\temp\test_bkp\pscx\pscx.psd1
If not, is "C:\temp\test_bkp" in your PSModulePath environment variable?

gbecerra1982 wrote Feb 2 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.

gbecerra1982 wrote Feb 17 at 12:09 PM

Could you help me to identity the issue please?

r_keith_hill wrote Feb 19 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
And paste the clipboard text in a comment on this page.

gbecerra1982 wrote Feb 19 at 2:25 AM

Hi,

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

Yes, I downloaded the latest version.

This is the command used by the ImportModule:

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

gbecerra1982 wrote Feb 19 at 2:27 AM

File attached

gbecerra1982 wrote Feb 19 at 2:29 AM

You can download the screenshot from here:

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

r_keith_hill wrote Feb 20 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}}

gbecerra1982 wrote Feb 20 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

r_keith_hill wrote Feb 25 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?

gbecerra1982 wrote Feb 25 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
AddAccelerator "wmidatetime" ([Pscx.TypeAccelerators.WmiDateTime])
AddAccelerator "wmitimespan" ([Pscx.TypeAccelerators.WmiTimeSpan])

Export nothing

Export-ModuleMember

SIG # Begin signature block

You can download the complete file from here:

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

Thanks a lot for your help :)

r_keith_hill wrote Feb 25 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.

gbecerra1982 wrote Feb 25 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 :)