powershell - remove-computer cmdlet access denied -


i trying create script remove computer domain using remove-computer -unjoincredentials domain\admin -passthru however, consistently receive error stating

remove-computer : failed unjoin computer 'web140127105714' domain 'domain.com' following error message: access denied. @ line:1 char:1 + remove-computer -unjoindomaincredential domain\admin -passthru + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : operationstopped: (web140127105714:string) [remove-computer], invalidoperationexception + fullyqualifiederrorid : failtounjoindomain,microsoft.powershell.commands.removecomputercommand

the account using domain administrator full access. have confirmed account can manually unjoin domian.

sounds op found answer, here powershell self elevating example future readers. add top of scripts , re-launch elevated don't have right click , 'run administrator'.

$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 elevation'   exit } ##################### # add scripts below # ##################### write-host 'elevatedcoderunshere'; write-host 'press key continue...' $null = $host.ui.rawui.readkey('noecho,includekeydown') 

powershell start-process script calls second script - how make 1 script only


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -