Powershell 禁止证书通知 [英] Powershell Suppress Certificate Notification

查看:91
本文介绍了Powershell 禁止证书通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个脚本,以使用 RDP-Protocoll 从 Windows 10 客户端连接到终端服务器.

I am writing a script to connect from a Windows 10 Client to a Terminal Server with the RDP-Protocoll.

背后的想法是:在这些瘦客户端上,我们有大约 20 个 RDP 文件.大约有 10 个密码需要保护.

The thought behind is: On these ThinClients we have about 20 RDP-Files. With about 10 of them, the password needs to be safed.

因此,如果您总是需要在每个新的瘦客户端上保存密码,那将是一项相当大的工作.

So it is quite a lot of work if you always have to save the password on every new ThinClient.

但我想我可以用powershell脚本解决这个问题.我只需要成功打开连接 1 次并保存凭据,然后进一步保存凭据.

But I thought I could solve this problem with a powershell script. I just have to open the connection 1 time successfully and save the credentials and further on the credentials are saved.

我先展示我的代码:

$Server = "xx.yy.zz.xx"
$User = "DOMAIN\User"
$password = "password"

cmdkey /generic:"$Server" /user:"$User" /pass:"$password"

mstsc /v:"$Server"

到目前为止,这是有效的.

This works so far.

但我总是收到此通知:

这是来自互联网的符号图片,因为我的通知是德语.完全一样,只是更容易理解.

This is a Symbol-Picture from the Internet, as my Notification is in German. It is exactly the same, just easier to understand.

即使我安装了证书,通知也会不断弹出.

Even if I install the certificate, the notification keeps popping up.

如何使用 Powershell 检查该字段,其中显示不再询问我是否连接到这台计算机?

How can I check the field with Powershell, where it says Don't ask me again for connections to this computer?

推荐答案

好的,我找到了解决方案!勾选不要再问我..."时会生成一个注册表项

Ok i found a solution! There is a registry-Key generated when you Tick "Dont ask me again..."

现在我只是用我的 Powershell 脚本添加了必要的注册表项..

Now i just added the necessary Registry Keys with my Powershell Script..

function Test-RegistryValue {

param (

 [parameter(Mandatory=$true)]
 [ValidateNotNullOrEmpty()]$Path,

[parameter(Mandatory=$true)]
 [ValidateNotNullOrEmpty()]$Value
)

try{

Get-ItemProperty -Path $Path | Select-Object -ExpandProperty $Value -ErrorAction Stop | Out-Null
 return $true
 }

catch{

return $false

}

}


#Certificate warning turn off
$exists = Test-RegistryValue -Path 'HKCU:\Software\Microsoft\Terminal Server Client' -Value 'AuthenticationLevelOverride'

if($exists -eq $False){
    reg add "HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client" /v "AuthenticationLevelOverride" /t "REG_DWORD" /d 0 /f 
}

像这样,它可以在没有此证书通知的情况下工作!

Like this it works without this certificate notification!

这篇关于Powershell 禁止证书通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆