微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在远程Powershell会话中保留凭据?

我有一个Azure文件共享,并希望在我的Azure VM中使用它 – 在使用cmdkey在VM上保留凭据并使用net use挂载之后.通过在 Windows Server 2012 R2上的本地Powershell会话中运行这些命令来测试这一点.

但我需要将此步骤添加到Azure部署脚本中. Azure Powershell脚本从我的笔记本电脑运行,连接到Azure订阅并使用大量变量从头开始构建VM.

想出使用Invoke-Command将变量从Azure Powershell脚本传递到新创建的VM上的远程Powershell会话.

$Session = New-PSSession -ConnectionUri $Uri -Credential $DomainCredential

$ScriptBlockContent = { 
Param ($Arg1,$Arg2,$Arg3)
cmdkey /add:$Arg1 /user:$Arg2 /pass:$Arg3}

Invoke-Command -Session $Session -ScriptBlock $ScriptBlockContent -ArgumentList ($Share,$AccountName,$Key)

错误

PS C:\> Invoke-Command -Session $Session -ScriptBlock $ScriptBlockContent -ArgumentList ($Share,$Key)
CMDKEY: Credentials cannot be saved from this logon session.

替换为cmdkey / list以检查语法,并且没有错误.

PS C:\> Invoke-Command -Session $Session -ScriptBlock $ScriptBlockContent
Currently stored credentials:
* NONE *

一个类似的问题(并且无法修复它)与Windows Update PowerShell模块(Invoke-WUInstall),它在VM上的本地Powershell会话上运行良好,但在通过远程Powershell启动时不会更新.

有办法解决这个问题吗?

由于Windows处理身份验证的方式无法使用CMDKEY通过远程PowerShell会话设置凭据,因此在使用CMDKEY时必须以交互方式完成.

从线程中引用Don Jones来寻找与您类似的答案:

That’s a limitation of the Cmdkey command – not really a PowerShell thing. But it’s related to the way Remotig handles credentials. The remote session doesn’t actually get a credential,it gets a delegated ticket,so there’s no token to actually save. That’s all by design,and not something you can reconfigure.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐