troubleshooting Question

Unable to Parse MBSA Log using PowerShell Script

Avatar of Mike
MikeFlag for United States of America asked on
Microsoft DevelopmentPowershellMicrosoft Server Apps
5 Comments1 Solution1347 ViewsLast Modified:
Hello,
I am having trouble getting the following script to parse List of MBSA logs located on my local hard drive. Every time I start the script I get the following error message below.  I have checked and verified my credentials have full access to that file directory  and the script is running as “administrator” when I start it.  The error message pointing to an error on Line 30 char: 38 as follows “[XML]$ScanResult = Get-Content <<<<  "C:\SecurityScans".. Can somebody take look at and see what I may be missing.  I have attached copy of the script along with this question.

Error Message
Get-Content : Access to the path 'C:\SecurityScans' is denied.
At C:\Users\admin\Desktop\MBSA Folder\MBSA Itemzed list\MBSA List of Missing Patches.ps1:30 char:38
+        [XML]$ScanResult = Get-Content <<<<  "C:\SecurityScans"
    + CategoryInfo          : PermissionDenied: (C:\SecurityScans:String) [Get-Content], UnauthorizedAccessException
    + FullyQualifiedErrorId : GetContentReaderUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetContentCommand

# Get Excel ready    
    $Excel = New-Object -comobject Excel.Application    
    $Excel.visible = $True     
    $Workbook = $Excel.Workbooks.Add()    
    $Info = $Workbook.Worksheets.Item(1)    
       
    # Create our column headers    
    $Info.Cells.Item(1,1) = "Computer Name"   
    $Info.Cells.Item(1,2) = "SDK Components Security Updates"   
    $Info.Cells.Item(1,3) = "SQL Server Security Updates"   
    $Info.Cells.Item(1,4) = "Windows Security Updates"   
    $Info.Cells.Item(1,5) = "BizTalk Server Security Updates"   
    $Info.Cells.Item(1,6) = "Exchange Security Updates"   
    $Info.Cells.Item(1,7) = "Office Security Updates"   
     
    # Add a little formatting    
    $Style = $Info.UsedRange    
    $Style.Interior.ColorIndex = 19    
    $Style.Font.ColorIndex = 11    
    $Style.Font.Bold = $True   
     
    $intRow = 2    
     
    # iterate over each .mbsa file    
    foreach ($file in $file)    
    {    
       [XML]$ScanResult = Get-Content "C:\SecurityScans"
       $Scanned = $ScanResult.SecScan.Check | select Name, Advice    
       $Server = $ScanResult.SecScan.Machine    
       foreach($Scan in $Scanned)    
       {    
          # if Advice doesn't start with a numeric value then set it equal to 0    
          if( $Scan.Advice -match '^(?<Cnt>[0-9]*)'){$Advice=$matches.cnt}    else{$Advice=0}    
                  
          $Style.Cells.Item($intRow, 1) = $Server   
                 
          switch ($Scan.Name)     
          {    
             "SDK Components Security Updates"   {$Style.Cells.Item($intRow, 2) = $Advice;break}    
             "SQL Server Security Updates"       {$Style.Cells.Item($intRow, 3) = $Advice;break}    
             "Windows Security Updates"          {$Style.Cells.Item($intRow, 4) = $Advice;break}    
             "BizTalk Server Security Updates"   {$Style.Cells.Item($intRow, 5) = $Advice;break}    
             "Exchange Security Updates"         {$Style.Cells.Item($intRow, 6) = $Advice;break}    
             "Office Security Updates"           {$Style.Cells.Item($intRow, 7) = $Advice;break}    
          }    
         
       }    
       $intRow = $intRow + 1    
    }
ASKER CERTIFIED SOLUTION
Qlemo
"Batchelor", Developer and EE Topic Advisor
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros