Meltdown patch Checker script for remote PCs.

Microsoft release this article for Meltdown checker but how can I use it to check my entire domain?
A bonus is to export result into CSV which will state if it's patched or not.
https://support.microsoft.com/en-hk/help/4073119/protect-against-speculative-execution-side-channel-vulnerabilities-in
GGHCAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
To do that, we need to modify the procedure to manually load the .psm1 file from a network location. Download the package from https://aka.ms/SpeculationControlPS, and extract the content in the location $scriptloc points to. Then run the following code.
$scriptloc = '\\server\share\SpeculationControl'

Get-ADComputer -Filter {Enabled -eq $true} | 
  Select -Expand Name |
  % {
    Write-Progress "Testing" -Status "$_"
    Write-Host "Testing $_"
    if (Test-Computer $_ -quiet -count 2)
    {
      Invoke-Command -ComputerName $_ -ArgumentList $scriptloc -ScriptBlock {
        param ($scriptloc)
        $execpol = Get-ExecutionPolicy -Scope CurrentUser
        Set-ExecutionPolicy Bypass -Scope CurrentUser -Force
        Import-Module $scriptloc\SpeculationControl.psd1 -Force
        Get-SpeculationControlSettings
        Set-ExecutionPolicy $execpol -Scope CurrentUser -Force
      } # | tee -var Result   
    } else {
      Write-Host -f Yellow "$_ is unreachable"
      $_ | Select @{n='PSComputerName'; e={$_}},
                  BTIDisabledByNoHardwareSupport, BTIDisabledBySystemPolicy, BTIHardwarePresent,
                  BTIWindowsSupportEnabled, BTIWindowsSupportPresent, KVAShadowPcidEnabled, KVAShadowRequired,
                  KVAShadowWindowsSupportEnabled, KVAShadowWindowsSupportPresent      
    }
  } |
  Export-CSV -NoType "$scriptloc\Results.csv"

Open in new window

If you want to add some output to the screen about the final result, use the commented tee line to store the result into a variable $Result you can query.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GGHCAuthor Commented:
Thanks Qlemo,! I think this may require Powershell remoting enabled which is a road block in my environment. Is there a way to get the similar results using PSExec for remote PCs. Maybe run the command against a list of computers from a txt file? I was trying to create something from pieces of your code but couldn't,.
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
I don't understand why PS Remoting should be a roadblock on server OS. Only administrative accounts may remote into servers.

Using psexec is possible but more painful, in particular when trying to evaluate the result, which can only be returned as text stream we need to parse for the final result.
psexec is prone to authentication issues.

You can see if the following code works for you. It will generate log files in the script folder, and expect psexec to be there too. The machine names to check are in servers.txt. Servers are checked against the CSV file - if already checked with results, the machine is skipped.
$scriptloc = '\\server\share\SpeculationControl'
$psexec = "$scriptloc\psexec.exe"
$usr    = 'domain\administrator
$pwd    = 'adminpwd'

$resultfile = "$scriptloc\Results.csv"

# Generate PS1 script file to execute remotely
@'
  $execpol = Get-ExecutionPolicy -Scope CurrentUser
  Set-ExecutionPolicy Bypass -Scope CurrentUser -Force -ea SilentlyContinue
  Import-Module .\SpeculationControl.psd1 -Force
  Get-SpeculationControlSettings 2>logfile.$($env:Computername).log | ConvertTo-CSV 
  Set-ExecutionPolicy $execpol -Scope CurrentUser -Force -ea SilentlyContinue
'@ | Set-Content $scriptloc\check-pc.ps1

# Get PCs already checked with results
if (Test-Path $resultfile)
{
  $checked = Import-CSV $resultfile -ea SilentlyContinue | ? { $_.BTIDisabledByNoHardwareSupport} | Select -Expand PSComputername
}

# Get-ADComputer -Filter {Enabled -eq $true} | Select -Expand Name |
Get-Content $scriptloc\servers.txt |
  ? { $_ -notin $checked} |
  % {
    $computername = $_
    Write-Progress "Testing" -Status "$computername"
    Write-Host "Testing $computername"
    if (Test-Connection $computername -quiet -count 1)
    {
      & $psexec \\$computername -u $usr -p $pwd powershell -ExecutionPolicy Bypass -Command "set-location $scriptloc; .\Check-pc.ps1" 2>errorfile.$computername.log |
        select-string '^[#"]' |
        convertFrom-CSV | Select @{n='PSComputerName'; e={$computername}}, *
    } else {
      Write-Host -f Yellow "$_ is unreachable"
      $_ | Select @{n='PSComputerName'; e={$computername}},
                  BTIDisabledByNoHardwareSupport, BTIDisabledBySystemPolicy, BTIHardwarePresent,
                  BTIWindowsSupportEnabled, BTIWindowsSupportPresent, KVAShadowPcidEnabled, KVAShadowRequired,
                  KVAShadowWindowsSupportEnabled, KVAShadowWindowsSupportPresent      
    }
  } |
  Export-CSV -Append -NoType $resultfile

Get-ChildItem $scriptloc\check-pc.ps1 | Remove-Item


# Module code available at https://gallery.technet.microsoft.com/scriptcenter/Speculation-Control-e36f0050/view/Discussions#content

Open in new window

The script has a lot of potential and real issues, so don't be surprised if it does not work as expected - too many factors, too many errors are to be considered here.
GGHCAuthor Commented:
Thank You!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.