但我需要将此步骤添加到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启动时不会更新.
有办法解决这个问题吗?
从线程中引用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 举报,一经查实,本站将立刻删除。