The main idea is to find out Certificates expiring on remote servers.
When the below command is run on individual servers, it gives the desired output.
Get-ChildItem -path Cert:\LocalMachine\My |select Issuer,NotAfter | select-string "^(?!.*MACHINE)" | out-file -filepath $logfile -append
But when i run it as a script to run on multiple computers it doesnt work. (WINRM is disabled)
$servers = Get-Content -path "C:\Servers.txt"
ForEach ($server in $servers)
{Enter-PSSession -computerName $server
Get-ChildItem -path Cert:\LocalMachine\My |select Issuer,NotAfter | select-string "^(?!.*MACHINE)" | out-file -filepath $logfile -append
exit-pssession}
Can somebody help me complete the script.