Query and list certificates installed on remote computers using Invoke-WMIobject

Below script lists installed certificates on remote computers having 'Token" in the subject stream. This works fine using Invoke-Command but I need to use Invoke-WMImethod as we don’t have PS enabled on lot of computers in domain. I have tried to replace the Invoke-command with Invoke-WMImethod in below script, but when I run it fails with this message - "A parameter cannot be found that matches parameter name ‘ScriptBlock’. I don’t know what am I missing here or I am making incorrect use of the remoting command. Would appreciate if someone can take a look in Forum and suggest to fix it.

Input file

$Servers = Get-Content “C:\Users\Downloads\servers.txt”
$ErrorActionPreference = ‘Stop’
$Array = @()
$cred = Get-Credential

Looping each server

foreach($Server in $Servers)
Write-Host Processing $Server -ForegroundColor yellow


Checking hostname of a server provided in input file

$hostname = ([System.Net.Dns]::GetHostByName("$Server")).hostname

Querying for certificates

$Certs = Invoke-WmiMethod -Class Win32_Process -Name Create -ArgumentList “gpupdate.exe /force” -ComputerName $Server -Credential $cred -ScriptBlock{ Get-Childitem Cert:\LocalMachine\Root } | Where-Object {$_.Subject -Match “Token-CA”}


If($hostname -and $Certs)
Foreach($Cert in $Certs)

Adding certificate properties and server name to object

$Object = New-Object PSObject
$Object | Add-Member Noteproperty “Server name” -Value $hostname
$Object | Add-Member Noteproperty “Certificate Subject” -Value $cert.Subject
$Object | Add-Member Noteproperty “Certificate expiration date” -Value $cert.notafter
$Object | Add-Member Noteproperty “Certificate thumbprint” -Value $cert.thumbprint

Adding object to an array

$Array += $Object
Write-Warning “Something went wrong”


To export to CSV

$Array | Export-Csv -Path C:\Users\Downloads\results.csv -Force -NoTypeInformation