我有以下脚本,它会在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
有没有办法在远程计算机上运行它,它可以查看该计算机证书存储而不是本地计算机?
我尝试了一些不同的方法但无法找到有效的方法
答案 0 :(得分:1)
确保已配置PSRemoting。然后,您可以使用 Invoke-Command 来完成工作。
$Computername= 'remotecomputer'
$RemoteMachine_cred =Get-Credential
Invoke-Command -ComputerName localhost -ScriptBlock {Get-ChildItem -Recurse cert: | select subject, notafter} -Credential $RemoteMachine_cred
配置PSRemoting的链接:
1) Use Remote Commands in PowerShell
2) Run PS Commands on Remote Computers
注意:您可以将所有脚本放在一个脚本块中,然后可以将其作为一个脚本块的值单次传递。
希望它有所帮助。