Switch to make PS Custom Object

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Curtis Smith Curtis Smith 8 months, 3 weeks ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #33414
    Profile photo of H Man
    H Man
    Participant

    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    
    } 
    
    #33439
    Profile photo of Curtis Smith
    Curtis Smith
    Participant

    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.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.