Avatar of Mike
Mike
Flag for United States of America asked on

Mbsacli.exe script

I am currently working on a script to scan list of network computers to see if our current network patch management process is working correctly. I am currently using "Microsoft Baseline Security Analyze" software to complete this task. Pacifically the use of “mbsacli.exe command line utility” to read from a text document (list the host computers) and check for missing patches…  I have completed the script in power shell editor but keep running it a problem with the script not reading the ‘servers.txt” file where I have list of about 200 computers to check as a test.

I have setup the patch dir for the output of reports to  “C:\PS\MBSA\Reports\NewReports" and the source of the documents “servers.txt” in the following location.” C:\PS\MBSA\servers.txt”. I use the following .\Get-MBSAStats.ps1 -h C:\PS\MBSA\servers.txt” as the input for the “Host” object but I get the following error when I run it it. I have attached the powershell script as part of this question if you wish to look at what I have done so far with the script.


Error Message:

cmd.exe : Microsoft Baseline Security Analyzer
At line:1 char:4
+ cmd <<<<  /c mbsacli /listfile "Host" /n OS+SQL+IIS+Password
    + CategoryInfo          : NotSpecified: (Microsoft Baseline Security Analyzer:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
Version 2.1.1 (2.1.2112.0)

(C) Copyright 2002-2009 Microsoft Corporation. All rights reserved.

Error: Cannot open file Host

There are no valid hosts, now exiting

mbsapowershellscript.txt
IT AdministrationVulnerabilitiesShell Scripting

Avatar of undefined
Last Comment
Mike

8/22/2022 - Mon
SterlingMcClung

Your script never uses the variable $Hosts in the script.  I suspect that the line:

$cmd = “cmd /c mbsacli /listfile ""Host"" /n OS+SQL+IIS+Password”

is meant to reference this variable and not the word "Host".  You may try something like this:

$cmd = “cmd /c mbsacli /listfile " + $Hosts + " /n OS+SQL+IIS+Password”

SterlingMcClung

Also, it looks like you would have to run it as:

.\Get-MBSAStats.ps1 -computers C:\PS\MBSA\servers.txt

using -computers instead of -h.

Mike

ASKER
Thanks for your help on this script "SterlingMcClung".......

             I updated the script with the updated string you suggested and replaced "-h" with "-computers" and got the following results below.  I used the " -computers" using both froms for the string on this script ( i.e. ""Host"" and " + Host + ")  and got the same thing..



Script  Error:

cmd.exe : Microsoft Baseline Security Analyzer
At line:1 char:4
+ cmd <<<<  /c mbsacli /listfile .\Get-MBSAStats.ps1 -computers C:\PS\MBSA\servers.txt /n OS+SQL+IIS+Password
    + CategoryInfo          : NotSpecified: (Microsoft Baseline Security Analyzer:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
Version 2.1.1 (2.1.2112.0)
(C) Copyright 2002-2009 Microsoft Corporation. All rights reserved.

Error: Cannot open file .\Get-MBSAStats.ps1

There are no valid hosts, now exiting
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
SterlingMcClung

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Mike

ASKER
complete