Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Add a domain user to Local Administrator Group using Alternate Credentails.

$
0
0

I wrote the following script to add a domain user to local admin group using alternate credentials. .

$comp = ""
$user = "Domain\User"
$pass = "password"

$str_computer = "servername"

$comp =  New-Object System.DirectoryServices.DirectoryEntry("WinNT://$str_computer, computer",$user,$pass)

$admgroup = $comp.Children.Find("administrators", "group")

$admgroup.Properties["member"].Add("$user")

The script fails at the last line with the error :

Exception calling "Add" with "1" argument(s): "The directory property cannot be found in the cache.
"
Does some know how to get that thing fixed. I have no clue where to go. I can invoke members of the local administartors group so I know that part works, but what am I doing wrong here.. please advise.

What should be the format of $user in $admgroup.Properties["member"].Add("$user"). I am new to AD, please advise.



Viewing all articles
Browse latest Browse all 21975

Trending Articles



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