Thursday, 18 December 2008

Create user in Linux via vbscript

You can combine with previous script to handle creating users for AD and linux together.
I use plink to connect and execute useradd and passwd commands.
Edit sudo file to give these permissions to a user execute two command useradd and sudo. Do not forget to encrypt vbscript.

Dim strUser, strName, strContainer
strUser = InputBox (" Create user","username","")
strName = InputBox ("Name Surname","Name Surname","")
'if you want usernames in lowercase
'strUser = Lcase(StrUser)

' Check username length
If Len(strUser) = 0 Then
wscript.echo "empty username ?"
End If

call Useradd(strUser)

Function Useradd(strUser)
Set WSHShell = WScript.CreateObject("WScript.Shell")
rc=WshShell.Run("c:\windows\plink.exe AUSERHAVINGSUDO@ -pw password useradd -d /home/"&

strUser &" -s /bin/csh -c " & strUser & " -m " & strUser , 1, FALSE)
if err.number <> 0 Then
wscript.echo "problem creating user for linux"
End if
End Function

No comments: