【问题标题】:remove-computer cmdlet access denied删除计算机 cmdlet 访问被拒绝
【发布时间】:2014-01-31 15:25:10
【问题描述】:

我正在尝试创建一个脚本以使用 remove-computer -unjoincredentials domain\admin -passthru 从域中删除计算机但是,我一直收到一条错误消息,指出

remove-computer : Failed to unjoin computer 'web140127105714' from domain 'domain.com' with the following error message: Access is denied. At line:1 char:1 + remove-computer -UnjoinDomainCredential domain\admin -PassThru + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (web140127105714:String) [Remove-Computer], InvalidOperationException + FullyQualifiedErrorId : FailToUnjoinDomain,Microsoft.PowerShell.Commands.RemoveComputerCommand

我使用的帐户是具有完全访问权限的域管理员。我已确认该帐户可以手动退出域。

【问题讨论】:

  • 我认为添加 -Force 开关没有帮助,对吧?您可以使用域管理员帐户远程访问计算机吗?
  • 只是好奇,您是在提升的 PowerShell 控制台上吗? IE。您是否右键单击并以管理员身份启动它?
  • 哇,阿迪尔,我不敢相信我什至还没有尝试过……因为我能够在非提升的控制台中加入域,所以可能是这种情况并没有向我注册。有没有办法在提升的权限下自动运行脚本?
  • 好吧,我首选的方法是使用“计划任务”,您可以选择将其作为“提升”运行

标签: powershell active-directory


【解决方案1】:

控制台上的某些操作要求您处于提升的 PowerShell 会话中。您可以通过右键单击它并选择“以管理员身份运行”来以管理员身份启动 PowerShell 会话。然后在该控制台会话中运行 remove-computer cmdlet。管理员 PowerShell 控制台的默认标题是“管理员:Windows PowerShell”。你可以这样识别窗口

【讨论】:

  • 如何以管理员身份运行 PS Remoting ?我使用 C:\Windows\sysnative\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File "\\server\temp\test.ps1" domain\user pass "C:\temp"
【解决方案2】:

听起来 OP 找到了他的答案,所以这里有一个 powershell 自我提升的例子,供未来的读者参考。添加到您的脚本顶部,它会在提升后重新启动,因此我们不必右键单击并“以管理员身份运行”。

$WID=[System.Security.Principal.WindowsIdentity]::GetCurrent();
$WIP=new-object System.Security.Principal.WindowsPrincipal($WID);
$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator;
If ($WIP.IsInRole($adminRole)){
}else {
  $newProcess = new-object System.Diagnostics.ProcessStartInfo 'PowerShell';
  $newProcess.Arguments = $myInvocation.MyCommand.Definition
  $newProcess.Verb = 'runas'
  [System.Diagnostics.Process]::Start($newProcess);Write-Host 'Prompting for Elevation'
  exit
}
#####################
# Add Scripts Below #
#####################
Write-Host 'ElevatedCodeRunsHere';
Write-Host 'Press any key to continue...'
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')

Powershell start-process script calls a second script - how to make one script only

【讨论】:

  • 其实我也在找那个!谢谢你真棒
【解决方案3】:

没有-unjoincredentials这样的参数

http://technet.microsoft.com/en-us/library/hh849816.aspx

【讨论】:

  • 对不起,这是我的错字。如报错所示,我使用-UnJoinDomainCredential
猜你喜欢
  • 2016-10-01
  • 2017-07-28
  • 1970-01-01
  • 1970-01-01
  • 2016-12-10
  • 1970-01-01
  • 1970-01-01
  • 2010-12-06
  • 2016-10-30
相关资源
最近更新 更多