kumar4755 / Powershell_Task1

0 stars 0 forks source link

Comparision Reports from Fireeye and a local report #1

Open kumar4755 opened 4 years ago

kumar4755 commented 4 years ago

Download Report from Fireeye Dashboard

Compare Hostnames in Fireeyedoc and Local existing Doc

  1. Identify the list hostnames that are in report 1 but not in 2
  2. Identify the list hostnames that are in report 2 but not in 1
  3. Last Sys info of hosts in Fireeye Dashboard
satyam763 commented 4 years ago

test2.zip

satyam763 commented 4 years ago

$reference = Import-Csv -Path D:\Dev\test1.csv $lookup = $reference | Group-Object -AsHashTable -AsString -Property Server $resultsNote = "NotMatching" $resultsNote1 = "Matching"

$results = Import-Csv -Path D:\Dev\test2.csv | foreach { $server = $.Server Write-Verbose "Looking for $server" if ($lookup.ContainsKey($server)) { $oldState = ($lookup[$server]).State } else { $oldState = "NotMatching" } if ($.State -ne $oldState) { [PSCustomObject]@{ Server = $server ResultNote = $resultsNote } } else { [PSCustomObject]@{ Server = $server ResultNote = $resultsNote1

    }
}

}

Sample outputs

$results | Export-Csv -Path D:\Dev\result.csv -NoType -Encoding ASCII

satyam763 commented 4 years ago

`$reference = Import-Csv -Path D:\Dev\test1.csv $lookup = $reference | Group-Object -AsHashTable -AsString -Property Server $resultsNote = "NotMatching" $resultsNote1 = "Matching"

$results = Import-Csv -Path D:\Dev\test2.csv | foreach { $server = $.Server Write-Verbose "Looking for $server" if ($lookup.ContainsKey($server)) { $oldState = ($lookup[$server]).State } else { $oldState = "NotMatching" } if ($.State -ne $oldState) { [PSCustomObject]@{ Server = $server ResultNote = $resultsNote } } else { [PSCustomObject]@{ Server = $server ResultNote = $resultsNote1

    }
}

}

Sample outputs

$results | Export-Csv -Path D:\Dev\result.csv -NoType -Encoding ASCII `

satyam763 commented 4 years ago

Please check ``

kumar4755 commented 4 years ago

$username="admin" $password="12345" $url = "http://testing-ground.scraping.pro/login" $ie = New-Object -com internetexplorer.application $ie.visible = $true $ie.silent = $true $ie.navigate($url)

Sleep while IE is busy. Check 10 times per second, adjust delay as needed

while($ie.Busy) { Start-Sleep -Milliseconds 10 }

IE is not busy with document anymore, pass credentials and click the logon

($ie.document.IHTMLDocument3_getElementByName("usr") |select -first 1).value = $username ($ie.document.IHTMLDocument3_getElementByName("pwd") |select -first 1).value = $password ($ie.document.IHTMLDocument3_getElementByName("Login") |select -first 1).click()

satyam763 commented 4 years ago

$HostID = import-csv D:\XYZABC\HostTest.csv

$HostString = foreach ($Item in $HostID) { "'" + $Item.host + "'," }

write-host $HostString

satyam763 commented 4 years ago

Declaration

$HostID = import-csv D:\XYZABC\HostTest.csv
$HostString = foreach ($Item in $HostID) { "'" + $Item.hostID + "'," }
write-host "$HostString"
$webServicesLogon = "/devices/entities/host-group-actions/v1?action_name=add-hosts"
$Header = @{
            accept = 'application/json'
            'content-type' = 'application/json'
        }
# Authentication
$bodyParams = @{action_parameters = @(
                @{  name = 'filter'
                    value = '(device_id:[' + ($HostString).TrimEnd(',') + '])'} | ConvertTo-JSON )

# Execution
try {
    $logonResult = Invoke-RestMethod -Uri $webServicesLogon -Method POST -Headers $Header -ContentType "application/json" -Body $bodyParams
    return $logonResult
}
catch {
    Write-Host "StatusCode: " $_.Exception.Response.StatusCode.value__
    Write-Host "StatusDescription: " $_.Exception.Response.StatusDescription
    Write-Host "Response: " $_.Exception.Message
    Return $false
}

}