You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于KeyTab的Kerberos认证PowerShell远程连接问题及集群CPU咨询

问题解答

1. Kerberos票据转PSCredential的方法不可行

你当前的思路存在本质错误:PSCredential的第二个参数要求是用户密码转换的SecureString,而非Kerberos票据数据。Kerberos缓存文件是二进制的加密票据(包含TGT或服务票据),并非用户明文密码,把它转成SecureString后,New-PSSession会将其当作用户密码发送给远程机器验证,自然会出现「用户名或密码不正确」的错误。

正确的Kerberos认证远程PowerShell方式是利用Windows集成身份验证,直接复用当前会话已获取的Kerberos凭证,无需手动创建PSCredential:

  1. 确保通过kinit获取到有效的TGT后,当前PowerShell会话能识别该Kerberos凭证(若使用MIT Kerberos,需确保其与Windows SSPI集成,或直接使用Windows内置的kinit);
  2. 直接调用New-PSSession时不指定-Credential参数,PowerShell会自动使用当前会话的Kerberos凭证完成认证:
$session = New-PSSession -ComputerName $remoteMachine

2. 更简便的集群CPU使用率获取方法

无需逐个创建会话,可直接批量查询远程机器:

方法一:批量Invoke-Command

# 定义集群机器列表
$clusterComputers = @("remote1.domain.com", "remote2.domain.com", "remote3.domain.com")

# 批量执行CPU查询,自动复用当前Kerberos凭证
Invoke-Command -ComputerName $clusterComputers -ScriptBlock {
    (Get-CimInstance Win32_Processor | Measure-Object LoadPercentage -Average).Average
} | Select-Object PSComputerName, @{Name='AverageCPU'; Expression={$_}}

方法二:直接用Get-CimInstance远程查询

无需建立持久会话,直接通过CIM协议查询:

$clusterComputers = @("remote1.domain.com", "remote2.domain.com")

Get-CimInstance Win32_Processor -ComputerName $clusterComputers |
    Group-Object PSComputerName |
    ForEach-Object {
        [PSCustomObject]@{
            ComputerName = $_.Name
            AverageCPU = ($_.Group | Measure-Object LoadPercentage -Average).Average
        }
    }

这两种方法都支持批量操作,且在已有有效Kerberos凭证的情况下,无需手动传入密码或凭证对象,简化了认证流程。


内容的提问来源于stack exchange,提问作者Chandru

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 17:44:53