rj07thomas

Find certificates

Jul 1st, 2023
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #Clears terminal screen
  2. Clear-Host
  3.  
  4. #Sets all error action
  5. $ErrorActionPreference= 'silentlycontinue'
  6.  
  7. Remove-Item .\collatedData.csv
  8.  
  9. $serverList = Get-ADComputer -LDAPFilter "(&(ObjectCategory=Computer)(OperatingSystem=*server*))" | Select-Object Name | Sort-Object Name
  10. $serverNames = $serverList.Name
  11.  
  12. ForEach ($server in $serverNames)
  13. {
  14.  
  15. C:\Progra~2\Nmap\nmap.exe -sS $server --script=ssl-cert -oX .\$server.xml
  16.  
  17. [xml]$allXml = Get-Content .\$server.xml
  18.  
  19. $allPorts = $allXml.nmaprun.host.ports.port
  20.  
  21. Foreach($port in $allPorts)
  22. {
  23. $portID = ""
  24. $commonName = ""
  25. $endDate = ""
  26. $portID = $port.portid
  27. $commonName = $port.script.table.elem[0]
  28. $endDate = $port.script.table[4].elem[1]
  29. $portIDString = $portID
  30. $commonNameString = $commonName
  31. $endDateString = $endDate
  32.  
  33. $collatedData = $server+"`t"+$portIDString+"`t"+$commonNameString.InnerText+"`t"+$endDateString.InnerText | Out-File .\collatedData.csv -Append
  34. $collatedData
  35. }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment