Author Posts

January 2, 2016 at 6:59 pm

I am using this snipit of code to parse mbsa files to an excell worksheet, but i would much rather create a ps object out of it. I am stuck on how to do that with the exsisiting switch.

Any help would be great

foreach ($file in $files.FullName)    
{    
   [XML]$ScanResult = Get-Content $file   
   $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 '^(?[0-9]*)'){$Advice=$matches.cnt}    else{$Advice=0}    
              
      $Style.Cells.Item($intRow, 1) = $Server   
             
      switch ($Scan.Name)     
      {    
         "Developer Tools, Runtimes, and Redistributables Security Updates"   {$Style.Cells.Item($intRow, 2) = $Advice;break}    
         "Windows Security Updates"          {$Style.Cells.Item($intRow, 3) = $Advice;break}    
         "Office Security Updates"           {$Style.Cells.Item($intRow, 4) = $Advice;break}    
      }    
     
   }    
   $intRow = $intRow + 1    
} 

January 4, 2016 at 6:51 am

That really depends on what you mean by creating a PS object of it. If you just remove the portion that sets the value in the excel document, then it will return the value to the pipeline instead. This would be a string object. If you are looking to create a custom powershell object with properties, then you would just need to define that and it would output.

      switch ($Scan.Name)     
      {    
         "Developer Tools, Runtimes, and Redistributables Security Updates"   {$Advice;break}    
         "Windows Security Updates"          {$Advice;break}    
         "Office Security Updates"           {$Advice;break}    
      }    

Obviously the above is not very useful since it is outputting the same thing for in every case. It would be good to provide a sample of what you are wanting to see so we can better understand what you are trying to accomplish.