Mbsacli.exe script

Mike
Mike used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
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”

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.

MikeSecurity

Author

Commented:
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
If the script that you posted is saved on your computer as Get-MBSAStats.ps1, then you need to run the following command in PowerShell:

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

Author

Commented:
complete

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial