gpt4 book ai didi

Powershell:字符串变量不是有效的十六进制字符串错误

转载 作者:行者123 更新时间:2023-12-03 16:45:09 24 4
gpt4 key购买 nike

我正在尝试创建一个 powershell 脚本来提取 Windows 服务器上证书的指纹,以便我可以在变量中使用此指纹,以便在创建 HTTPS 监听器的另一个命令中使用它。

我已经成功地创建了使用以下命令的第一步:

$thumbprint = (get-childitem -path cert:\localmachine\my | where-object {$_.subject -match $hostname+".xxx.com"}).thumbprint

所以现在我将指纹保存在一个变量中。

然后我尝试使用以下命令,如果我手动输入 $thumbprint 值的内容,该命令将起作用:

winrm create winrm/config/listener?Address=*+Transport=HTTPS '@{Hostname="$hostname";CertificateThumbprint="$thumbprint"}'

运行此命令时出现以下错误:

Message = The WS-Management service cannot process the configuration request because the certificate thumbprint in the request is not a valid hex string: $thumbprint.

有谁知道我该如何解决这个问题?

这有效(手动输入相同的值):

winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname="xxx.xxx.xxx";CertificateThumbprint="AF1D0F82070C4E3692BBF43747BAE74DED74A40A"}'

$thumbprint 变量的内容是 AF1D0F82070C4E3692BBF43747BAE74DED74A40A

最佳答案

由于您使用的是 PowerShell,因此您可以使用 WSMan PowerShell 提供程序来配置 WS-Management 服务:

New-Item WSMan:\localhost\Listener -Address * -Transport HTTPS -HostName $hostname -CertificateThumbPrint $thumbprint

关于Powershell:字符串变量不是有效的十六进制字符串错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31049744/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com