Good day all,
I have been banging my head against the wall on this one... I have powershell 3.0 and am trying to create a script to import 420 users into a local server. The script is getting various errors while adding the user to the group. I have followed a few different threads and it doesn't seem to workout.
Here is sample data:
User Pass
1-Installer MyPassword1
Acton MyPassword1
These are the links that I have been using to come up with this version of code:
http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/9d8bc8e8-8059-42fe-bb7d-2c9ecb3b6cb3
http://richardspowershellblog.wordpress.com/2008/04/17/local-users-and-groups/
They are the foundation, but I have been researching for a long time now and I think I have hit the end... I am using the Powershell ISE to debug it and I get the following 2 errors with slight different variations of the code:
Exception calling "Add" with "1" argument(s): "A member could not be added to or removed from the local group because the member
does not exist. (Added a sleep 10 to see if it needed time to refresh)
The following exception occurred while retrieving member "Add": "The network path
was not found. (This was when I changed the "." to env:computername")
Method invocation failed because [System.DirectoryServices.DirectoryEntry] doesn't
contain a method named 'op_Addition'. (Now this one was generated because I changed the concatenation from a "+=" to just a "+")
So, what I have found to be the problem is the following line: "$objuser = [ADSI]"WinNT://./" += $_.User" because in the debugger, I do not see the user value being assigned to the $objuser variable. It just stays blank and causes more errors...
$objgroup = [ADSI]"WinNT://$env:ComputerName/FTPUsers,group" $target = [ADSI]"WinNT://$env:ComputerName" $root = "E:\FTPRoot\" Import-Csv "C:\test.txt" -delimiter "`t" | ForEach-Object { $userinfo = $_.User $password = $_.Pass $newuser = $target.Create("user", $userinfo) $newuser.SetPassword($password) $newuser.SetInfo() $newuser.psbase.InvokeSet('AccountDisabled', $false) $newuser.userflags = 65536 -bor 64 $newuser.HomeDirectory = $root += $userinfo $newuser.SetInfo() sleep 10 $objuser = [ADSI]"WinNT://./" += $_.User $objgroup.Add($objuser.Path) $userinfo = "" $password = "" }
Any suggestions?
Tico