pester / Pester

Pester is the ubiquitous test and mock framework for PowerShell.
https://pester.dev/
Other
3.11k stars 473 forks source link

Method invocation failed because... (PS v2 Windows 2008 R2) #526

Closed SwarfegaGit closed 7 years ago

SwarfegaGit commented 8 years ago

My management server runs PS v5. Target servers mostly run v2. From the management server I can do tests with Enter-PSSession fine but if I copy the Pester module to a server running PS v2 and run the tests directly from the server I get errors.

    [-] Windows is activated. 2.9s
      RuntimeException: Method invocation failed because [Deserialized.System.Management.ManagementObject#root\cimv2\Sof
twareLicensingProduct] doesn't contain a method named 'GetType'.
      at line: 6 in C:\Users\Me\Desktop\Pester\3.4.0\Functions\Assertions\BeNullOrEmpty.ps1

The test is...

        It 'Windows is activated.' {
            (Invoke-Command -Session $Session -ScriptBlock {
                Get-WmiObject -Class SoftwareLicensingProduct | Where-Object -FilterScript { $_.LicenseStatus -Match '1' }
            }) |
            Should Not BeNullOrEmpty
        }

It also fails on

        It 'Files are updating.' {
            (Invoke-Command -Session $Session -ScriptBlock {
                If (Test-Path "$env:ProgramFiles\SoftwareApp\Downloads") {
                    Get-ChildItem -Path "$env:ProgramFiles\SoftwareApp\Downloads" -Filter '*.7z' -ErrorAction SilentlyContinue | 
                    Where-Object { $_.LastWriteTime.Date -gt ((Get-Date).Date).AddDays(-2) }
                }
            }) |
            Should Not BeNullOrEmpty
        }

With the same error...

RuntimeException: Method invocation failed because [Deserialized.System.IO.FileInfo] doesn't contain a method named 'GetType'.

Each time I am using the "Not BeNullOrEmpty". The rest of my tests don't use Not so possibly why only these two tests are failing?

dlwyatt commented 8 years ago

Weird. All objects should have GetType(), it's defined on the root object class of .NET. I'd say that this is probably a PowerShell Remoting bug that existed in v2, and they fixed in later versions.

SwarfegaGit commented 8 years ago

Possibly. Despite these scripts running locally I am literally lifting and shifting them to a local machine, so a PSSession is still being created to itself when ran locally. I can't figure out a way to make one test.ps1 file that will be user friendly when ran locally or remote.

Happy to get this issue ignored if you're happy it's a v2 bug.

it-praktyk commented 7 years ago

I assume that the issue can be closed now. Feel free to reopen if you need more assistance.