Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Inconsistent output using Export-Csv - returns partial results -OR- System.Object[]

$
0
0

As it will become clear, I am new to scripting and even newer to PowerShell.  That said, I have searched for an answer to these specific problems now going on 3 days; including the three that were recommended as I began this.  Time to ask for a fish (or at the very least a link to a fish) rather than trying to catch the fish myself.

I captured most of my notes within the PowerShell script itself along with example links that demonstrate the issues.  In addition to being open to suggestions on how to clean up this script, the jist of my 3 problems are:

  1. Problem 1 and 3 - When the page I am searching has multiple results, I get unreliable output; particularly in the .csv.  Either a.) I only get one of the results when there should be multiples pulled off the page or b.) I get "System.Object[]"
  2. Problem 2 - When a pattern regex is found multiple times though the actual text itself differs, I would like only the unique occurrences.

Thanks to everyone in this community who is always so helpful and patient.

$output = @()
$web = New-Object Net.WebClient
$urls = get-content "C:\Scripts\ResearchURLs.txt"
#If you want to build this file here are four good example URLS:
    #Example URL1: https://securelist.social-kaspersky.com/en/advisories/59781
    #Example URL2: http://www.viruslist.com/fr/advisories/59781
        #This is just the French version of Example 1, but sometimes has more information
    #Example URL3: https://securelist.social-kaspersky.com/en/advisories/59003
    #Example URL4: http://www.viruslist.com/fr/advisories/59003
        #Again the French version of URL3
$FormatEnumerationLimit = 150
foreach($url in $urls){
$results = $web.DownloadString("$url")
$matchesCVE = $results | Select-String '(?<n>CVE-\d+-\d+)' -AllMatches
#Problem #1 - I can only get the output in a .txt file.  The .csv only shows System.Object[].
    #Example of both outputs shown in output notes.
#Problem #2 - The same CVE may appear on the page more than once, so it repeats over and over in the output.
    #Is there a way to grab only every unique match?
    #I would also like to clean this up as much as possible and grab description from both sites as well as the original advisory.  Haven't figured that one out yet.
$matchesImpact = $results | Select-String -Pattern ("Denial of Service","DoS","Exposure of sensitive information","Manipulation of data","System access","Cross Site Scripting","Unknown","Hijacking","Security Bypass","Privilege Escalation","Spoofing") -AllMatches
#Problem 3 - When this works, it only matches one of the patterns
        #I say "when it works" because, (as with advisory 59003) there should be 2 impacts. 
        #The .txt and .csv both only show Exposure of sensitive information.
if ($matches.Matches){
$Object = New-Object PSObject
$Object | add-member Noteproperty URL               $url
$Object | add-member Noteproperty CVE               $matchesCVE.Matches.value
$Object | add-member Noteproperty Impact            $matchesimpact.Matches.value

$output+=$Object}
}
$output | Export-Csv "C:\Scripts\ResearchOutput.csv" -NoTypeInformation -force
    #Example of .csv file output:
        #URL                                                            CVE                Impact
        #https://securelist.social-kaspersky.com/en/advisories/59003	System.Object[]    Exposure of sensitive information
        #http://www.viruslist.com/fr/advisories/59003                   System.Object[]    Exposure of sensitive information
        #https://securelist.social-kaspersky.com/en/advisories/59781	System.Object[]    System.Object[]
        #http://www.viruslist.com/fr/advisories/59781	                System.Object[]    System.Object[]
$output | Format-Table -AutoSize | Out-String -Width 4096 | Out-File "C:\Scripts\ResearchOutput.csv" -force
    #Example of .txt file output:
        #URL                                                         CVE                                                                                        Impact                                             
        #---                                                         ---                                                                                        ------                                             
        #https://securelist.social-kaspersky.com/en/advisories/59003 {cve-2014-0497, CVE-2014-0497, CVE-2014-0497, CVE-2013-1500}                               Exposure of sensitive information                  
        #http://www.viruslist.com/fr/advisories/59003                {CVE-2013-1500, CVE-2013-1500}                                                             Exposure of sensitive information                  
        #https://securelist.social-kaspersky.com/en/advisories/59781 {cve-2014-0497, CVE-2014-0497, CVE-2014-0497, CVE-2014-0537, CVE-2014-0539, CVE-2014-4671} {Security Bypass, Security Bypass}                 
        #http://www.viruslist.com/fr/advisories/59781                {CVE-2014-0537, CVE-2014-0537, CVE-2014-0539, CVE-2014-0539, CVE-2014-4671, CVE-2014-4671} {Security Bypass, Security Bypass, Security Bypass}

Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>