powershell - 我可以以不同的用户身份执行安装吗?
问题描述
我们需要使用我们创建的特定域帐户执行以下命令,但我无法将命令传递给新的 Powershell 会话。我得到的错误是
“...目录名无效”
但是,当我执行一些简单的操作(例如使用相同的代码运行 IE)时,一切正常。
##Create new credential
$username = "DOMAIN\Username"
$password = "P@ssword"
$credentials = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force))
##ScriptBlock to pass to new PS Session started with new credential
$ScriptBlock = {
$args = "/s"
$username = "DOMAIN\Username"
$password = "P@ssword"
$credentials = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force))
Start-Process -FilePath C:\TEMP\WinMagic\SecureDoc_64.exe -WorkingDirectory C:\TEMP\WinMagic\ -credential $credentials
}
##Execute new powershell session with new credential and scriptblock
Start-Process -FilePath powershell.exe -credential $credentials -ArgumentList "-noexit" , {$ScriptBlock}
解决方案
推荐阅读
- c++ - 为什么我不能读“”,空格,作为一个字符
- symbolic-math - 象征性地优化表达式-找出等式 Maple 2018 中的数值异常可能性
- ios - 在 MacOS 错误中弃用 i386 架构
- tensorflow - tensorflow Seq2seq模型:推理结果与预期完全不同
- java - Netbeans 无法导入 FileUtils 包?
- android - 点击屏幕,打开被点击的布局
- python - Python - pandas ExcelFile/read_excel - 数据导入在第一个空行处停止
- linux - 波浪号有什么不同“~/
“对~/” " 在 Shell 脚本中 - python - Pandas 数据框填充索引之间的值
- json - 如何在python中的大型JSON文件中产生字典