使用PowerShell远程访问证书存储



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

$asset = $env:COMPUTERNAME
Set-Location cert:LocalMachineMy
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-command 完成工作。

$Computername= 'remotecomputer'
$RemoteMachine_cred =Get-Credential
Invoke-Command -ComputerName $Computername  -ScriptBlock {Get-ChildItem -Recurse cert: | select subject, notafter} -Credential $RemoteMachine_cred

链接以配置psremoting:

1)在PowerShell中使用远程命令

2)在远程计算机上运行PS命令

注意:您可以将所有脚本都放在脚本块中,然后可以将其作为单次镜头的值传递。

希望它有帮助。

最新更新