Wednesday 10 October 2012

Could not start the net logon service

c:\>netsh winsock reset

Network card not getting an IP address

or more accurately...

When I attempt to logon to a domain I just joined I
cannot and when i go into services the net logon service
is stopped I attempt to start it and get this message -

Could not start the net logon service on the local
computer. Error 10106: The requested service provider
could not be loaded or initialized.
Solution:
How to determine and to recover from Winsock2 corruption in Windows Server 2003, in Windows XP, and in Windows Vista

http://support.microsoft.com/?kbid=811259

Tuesday 9 October 2012

Powershell: Adding users to active directory with a csv


Creating users in AD from a csv file using Powershell

Using Import-Csv and New-ADUser

Some examples in the links
this is good:
http://gallery.technet.microsoft.com/scriptcenter/ed20b349-9758-4c70-adc0-19c5acfcae45
better than this:
http://social.technet.microsoft.com/Forums/en-US/winserverDS/thread/374dca0b-6b93-4a77-b53b-51602b2b4544/

And worth a look? simple automation straight from a csv, and  adding to a group also
http://www.simple-talk.com/sysadmin/exchange/active-directory-management-with-powershell-in-windows-server-2008-r2/

Having problems with execution? see:
http://technet.microsoft.com/en-us/library/ee176949.aspx

Import-Module ActiveDirectory
$Users = Import-Csv ".\myusers.csv" 
foreach ($User in $Users) 

    $OU = "OU=MyUsers,OU=MyStuff,DC=mydomain,DC=local,DC=com"
    $Detailedname = $User.firstname + " " + $User.lastname
    $Firstname = $User.Firstname
    $FirstLetterFirstname = $Firstname.substring(0,1) #not used this but left it in
    $SAM =  $User.Firstname.tolower() + "." + $user.lastname.tolower()
    $userprinci = $SAM + "@mydomain.local.com"
    $logonscript = "logscript.vbs"
    $homedir = "\\server\myarea\" + $SAM + "\My Documents"
    #tried this alternative
    #$homedir = "\\server\myarea\%username%\My Documents"
    New-ADUser -Name $Detailedname -SamAccountName $SAM -UserPrincipalName $userprinci -DisplayName $Detailedname -GivenName
$user.firstname -Surname $user.lastname -Path $OU -HomeDrive "H:" -HomeDirectory $homedir -scriptpath  $logonscript    -
PasswordNeverExpires $True -PassThru
#the password is blank on this example
}



Still issue with creating home directory for user, seems that i have to create this after by using the %username%, then apply this, then add My Documents.

I dont know if this is due to the user not being in a group(i.e. with correct privileges) or what. But cannot have the user in a group till user exists anyway!!??

So therefore I also needed to manually add to group.

This is the part mentioned earlier that adds users to groups, a bit pointless for now
add users to group"OU=MyUsers,OU=MyStuff,DC=mydomain,DC=local,DC=com"  |  ForEach-Object {Add-ADGroupMember -Identity 'ggGroupName' -Members $_}