Quantcast
Channel: PowerShell
Viewing all articles
Browse latest Browse all 15370

Add a user to local Admin Group

$
0
0
Powershell
$name=Read-Host'What is your username?'$DomainUser=$name$LocalGroup="Administrators"$Computer=$env:computername$Domain=$env:userdomain([ADSI]"WinNT://$Computer/$LocalGroup,group").psbase.Invoke("Add",([ADSI]"WinNT://$Domain/$DomainUser").path)

I am looking to work this small snipit of code into a larger script. I am looking to make this work but I get this error:Exception calling "Invoke" with "2" argument(s): "Number of parameters specified does not match the expected number."
At line:8 char:1
+ ([ADSI]"WinNT://$Computer/$LocalGroup,group").psbase.Invoke("Add",([A ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodTargetInvocation

I figure there is something simple i am missing.

...


Viewing all articles
Browse latest Browse all 15370

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>