加入收藏 | 设为首页 | 会员中心 | 我要投稿 云计算网_宿迁站长网 (https://www.0527zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Windows > 正文

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

发布时间:2021-03-06 01:45:33 所属栏目:Windows 来源:网络整理
导读:我有一个Azure文件共享,并希望在我的Azure VM中使用它 – 在使用cmdkey在VM上保留凭据并使用net use挂载之后.通过在 Windows Server 2012 R2上的本地Powershell会话中运行这些命令来测试这一点. 但我需要将此步骤添加到Azure部署脚本中. Azure 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.

(编辑:云计算网_宿迁站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!