perlestius / Zabbix_Templates

Zabbix Templates
13 stars 8 forks source link

[WMICheckOK] not working due to some strange behaviour of Get-WmiObject Asjob for Remote Computer #4

Closed pcamelio closed 1 year ago

pcamelio commented 2 years ago

OS : Windows 2019 Get-WmiObject with ComputerName and -AsJob is not working properly, at least for me.

QuickandDirt solution to overcome the problem Replace

            "WMICheckOK" {
                $WMIQuery = "SELECT * FROM DfsrConfig"
                $j = InvokeCommand -ComputerName $PartnerName -ScriptBlock {Get-WmiObject  `
                                   -Namespace $DFSNamespace `
                                   -Query $WMIQuery `
                                   -ErrorAction Ignore -AsJob }

                [void](Wait-Job $j -Timeout $RequestTimeout)
                [Boolean]($j.State -eq "Completed")
            } 

with

          "WMICheckOK" {
                $WMIQuery = "SELECT * FROM DfsrConfig"
                Try{
                    $j = Get-WmiObject -ComputerName $PartnerName `
                                       -Namespace $DFSNamespace `
                                       -Query $WMIQuery `
                                       -ErrorAction Ignore
                    [Boolean]($j.PSComputerName -eq "$PartnerName")            
                }catch{
                    [Boolean]($j.PSComputerName -eq "$PartnerName")
                }
perlestius commented 2 years ago

Get-WmiObject with ComputerName and -AsJob is not working properly, at least for me.

What do you mean? Please, describe the issue in more detail. What is PS version ($PSVersionTable)? Are actual Windows updates installed?

pcamelio commented 2 years ago

Windows 2019 Server Core Server up to date

Name                           Value
----                           -----
PSVersion                      5.1.17763.2931
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17763.2931
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
perlestius commented 2 years ago

Ok. And what do you mean by "some strange behaviour"?

pcamelio commented 2 years ago

This kind of problem.

https://stackoverflow.com/questions/2678163/get-wmiobject-fails-when-run-asjob

I know it is a very old thread :)

I made some tests with server on the same subnet - ie not fw between - unsuccessfully.

As we apply a lot of gpo to enforce security for our servers it can be a side effect. We have to make some tests on fresh Infrastructure. I let you know what is going on.

Best regards Philippe

Le 18 juin 2022 15:09, perlestius @.***> a écrit :

Ok. And what do you mean by "some strange behaviour"?

— Reply to this email directly, view it on GitHubhttps://github.com/perlestius/Zabbix_Templates/issues/4#issuecomment-1159462465, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AJSHY64LMYYGAIOU7YMJQU3VPXDBTANCNFSM5YG2DSTQ. You are receiving this because you authored the thread.Message ID: @.***>

[ { @.": "http://schema.org", @.": "EmailMessage", "potentialAction": { @.": "ViewAction", "target": "https://github.com/perlestius/Zabbix_Templates/issues/4#issuecomment-1159462465", "url": "https://github.com/perlestius/Zabbix_Templates/issues/4#issuecomment-1159462465", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { @.": "Organization", "name": "GitHub", "url": "https://github.com" } } ]

perlestius commented 1 year ago

It seems, you have firewall issue. See here for more information.