gpt4 book ai didi

powershell - 使用 Invoke-Command 时提升的权限

转载 作者:行者123 更新时间:2023-12-03 00:08:33 24 4
gpt4 key购买 nike

我正在尝试使用 Invoke-Command 将 MSI 部署到远程计算机,请参见下文。

如果我以“Domain\Administrator”身份运行此脚本,它会起作用,如果我尝试以指定帐户运行此脚本,则 MSI 将无法安装。我已经验证了我正在运行的帐户在所有服务器上都具有本地管理员权限。

如果帐户是本地管理员的成员,是否有办法让 PowerShell 提升帐户的权限?

我想避免在脚本本身中保存凭据。

$cred = Get-Credential
$MSISource = "E:\DeploymentTool\Deploy.msi"
$csv = Import-Csv "C:\Scripts\Deploylist.csv"
$csv | ForEach-Object {
$Server = $_.Server
Copy-Item $MSISource -Destination "\\$Server\E$\temp\Deploy.msi" -Force
Invoke-Command -ComputerName $Server -Credential $Cred -ScriptBlock {
Msiexec /i "E:\temp\Deploy.msi" /quiet /qn /norestart /log E:\temp\MSIInstall.txt
}

最佳答案

我遇到了类似的问题。我想使用 invoke-command 在远程计算机上安装 node.msi。

对于提升,我们可以在 Start-Process 命令中使用 -Verb RunAs。更新后的代码写在下面。

$cred = Get-Credential
$MSISource = "E:\DeploymentTool\Deploy.msi"
$csv = Import-Csv "C:\Scripts\Deploylist.csv"
$csv | ForEach-Object {
$Server = $_.Server
Copy-Item $MSISource -Destination "\\$Server\E$\temp\Deploy.msi" -Force
Invoke-Command -ComputerName $Server -Credential $Cred -ScriptBlock {
start-process powershell.exe -verb runas -argumentlist ('Msiexec /i "E:\temp\Deploy.msi" /quiet /qn /norestart /log E:\temp\MSIInstall.txt')}

现在,如果这对具有本地管理员权限的帐户产生如下错误。

由于错误无法运行此命令:此操作需要交互式窗口站。

我在注册表中做了以下更改,因为 key 不存在以使其工作 -

enter image description here

关于powershell - 使用 Invoke-Command 时提升的权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55121071/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com