Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $RemoteServerList = "Server1","Server2"
- $RemoteWebCertList = @()
- foreach ($Server in $RemoteServerList) {
- try {
- $username = "Username"
- $password = "Password"
- $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
- $S = New-PSSession -ComputerName $Server -Credential $cred
- $RemoteServerCertList += Invoke-Command -Session $S -ScriptBlock {
- $Store = New-Object System.Security.Cryptography.X509Certificates.X509Store("MY","LocalMachine")
- $Store.Open("ReadOnly")
- $store.Certificates | Select-Object *,@{Name="PSComputerName"}
- }
- Remove-PSSession $S
- }
- catch {
- Write-Host "Error Connecting to remote server $Server, Please verify connectivity and permissions"
- }
- $RemoteWebCertList += $RemoteServerCertList
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement