Advertisement
Guest User

Untitled

a guest
Jun 24th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. $RemoteServerList = "Server1","Server2"
  2.  
  3. $RemoteWebCertList = @()
  4.  
  5. foreach ($Server in $RemoteServerList) {
  6.  
  7. try {
  8.  
  9. $username = "Username"
  10.  
  11. $password = "Password"
  12.  
  13. $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
  14.  
  15. $S = New-PSSession -ComputerName $Server -Credential $cred
  16. $RemoteServerCertList += Invoke-Command -Session $S -ScriptBlock {
  17.  
  18. $Store = New-Object System.Security.Cryptography.X509Certificates.X509Store("MY","LocalMachine")
  19.  
  20. $Store.Open("ReadOnly")
  21.  
  22. $store.Certificates | Select-Object *,@{Name="PSComputerName"}
  23.  
  24. }
  25.  
  26. Remove-PSSession $S
  27.  
  28. }
  29.  
  30. catch {
  31. Write-Host "Error Connecting to remote server $Server, Please verify connectivity and permissions"
  32. }
  33.  
  34. $RemoteWebCertList += $RemoteServerCertList
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement