使用Powershell远程访问证书存储

使用Powershell远程访问证书存储,powershell,Powershell,我有以下脚本,它在本地计算机上带回我们的VPN客户端所需的所有证书,并显示到期日期: $asset = $env:COMPUTERNAME Set-Location cert:\LocalMachine\My Write-Host = "Asset ID:"$asset Get-ChildItem -Recurse cert: | select subject, notafter write-host "`n" Read-Host "Press any key to exit..."

我有以下脚本,它在本地计算机上带回我们的VPN客户端所需的所有证书,并显示到期日期:

$asset = $env:COMPUTERNAME

Set-Location cert:\LocalMachine\My

Write-Host = "Asset ID:"$asset

Get-ChildItem -Recurse cert: | select subject, notafter

write-host "`n"

Read-Host "Press any key to exit..."

(Get-Host).SetShouldExit(0)
它在我的本地机器上运行良好,请带回以下内容:

Subject                                              NotAfter                                            
-------                                              --------                                            
CN=HW008551D.hca.local                               21/07/2018 09:46:08                                
有没有一种方法可以在远程机器上运行此操作,它查看的是该机器的证书存储,而不是本地机器


我尝试了几种不同的方法,但找不到任何有效的方法

请确保已配置PSRemoting。然后您可以使用Invoke命令来完成您的工作

$Computername= 'remotecomputer'
$RemoteMachine_cred =Get-Credential
Invoke-Command -ComputerName localhost -ScriptBlock {Get-ChildItem -Recurse cert: | select subject, notafter} -Credential $RemoteMachine_cred
用于配置PSRemoting的链接:

(一)

(二)

注意:您可以将所有脚本放在scriptblock中,并且可以在单次快照中将其作为scriptblock的值传递


希望对您有所帮助。

Invoke命令-computername$asset-scriptblock{Get ChildItem-Recurse cert:|选择主题,notafter}
谢谢您的帮助。我已经在一个测试网络上进行了测试,效果非常好,不幸的是,我们的域名设置方式,我无法让它远程成功运行。我已经使用一个批处理文件创建了一个变通方法,该批处理文件在机器上本地运行,这样就可以解决问题。再次感谢。当我尝试从远程计算机读取所有证书时,出现以下问题: