use Win32; use Win32::Perms; use Win32::AdminMisc; use Win32::NetAdmin; use Win32::lanman; use Win32::OLE; &CreateUser($login_name, $fullname, $type, $ou, $password, $share); &makeHomefolder($login_name, $homeDir, $homeShare, $type, $share); sub makeHomefolder { print "Creating Users Home Folder $_[1]\n"; system ("mkdir $_[1]"); print "\nModifying Security on $_[0] Home Folder\n"; $Dir = new Win32::Perms( "$_[1]") || die; $Dir->Remove(-1); $Dir->Allow(Administrators,Win32::Perms::FULL_CONTROL_DIR,Win32::Perms::DIR); $Dir->Allow(Administrators,Win32::Perms::FULL_CONTROL_FILE,Win32::Perms::FILE); $Dir->Set(); $Dir->Allow($_[0],Win32::Perms::FULL_CONTROL_DIR,Win32::Perms::DIR); $Dir->Allow($_[0],Win32::Perms::FULL_CONTROL_FILE,Win32::Perms::FILE); $Dir->Set(); print "\n\nCreating Share $_[4] on $_[0] Home Directory\n"; #the below code only works when i execute on the NAS_SERVER if(!Win32::Lanman::NetShareAdd("\\\\NAS_SERVER", {'netname' => "$_[4]", # share name type => Win32::Lanman::STYPE_DISKTREE, # share type remark => '$_[3] share', # remark permissions => Win32::Lanman::ACCESS_ALL, max_uses => 3, path => "$_[1]", })) { print "Sorry, something went wrong; error: "; # get the error code print Win32::Lanman::GetLastError(); exit 1; } print "\nModifying Security on User Share\n"; #the below code only works when i execute on the NAS_SERVER $path = "\\\\MAXST2\\$_[4]"; $Dir = new Win32::Perms("share:".$path ) || warn "Can not create perm for \\\\NAS_SERVER\\$_[4] \n"; $Dir->Remove(-1); $Dir->Allow(Administrators,Win32::Perms::FULL_CONTROL_DIR,Win32::Perms::DIR); $Dir->Allow(Administrators,Win32::Perms::FULL_CONTROL_FILE,Win32::Perms::FILE); $Dir->Set(); $Dir->Allow($_[0],Win32::Perms::FULL_CONTROL_DIR,Win32::Perms::DIR); $Dir->Allow($_[0],Win32::Perms::FULL_CONTROL_FILE,Win32::Perms::FILE); $Dir->Set(); } #the below code only works when i execute on the MAIN_SERVER sub CreateUser { print "$_[3]\n"; print "$_[0]\n"; # openLDAP connection $Win32::OLE::Warn = 3; # Taken from $ADS_USER_FLAG_ENUM my $ADS_UF_NORMAL_ACCOUNT = 512; my $objParent = Win32::OLE->GetObject("LDAP://" . $_[3]); my $objUser = $objParent->Create("user", "cn=" . $_[0]); $objUser->Put("sAMAccountName", $_[0]); $objUser->Put("userAccountControl", $ADS_UF_NORMAL_ACCOUNT); $objUser->SetInfo; $objUser->{'HomeDirectory'} = "\\\\NAS_SERVER\\$_[5]"; $objUser->{'HomeDrive'} = 'H:'; $objUser->{'displayName'} = $_[1]; $objUser->{'Description'} = $_[2]; $objUser->{'userPrincipalName'} = "$_[0]\@domain.net"; $objUser->SetPassword($_[4]); $objUser->{AccountDisabled} = FALSE; $objUser->SetInfo; Win32::AdminMisc::UserSetMiscAttributes( '', $_[0], USER_FLAGS, UF_DONT_EXPIRE_PASSWD | UF_PASSWD_CANT_CHANGE ); } #I would like to be able to execute all code from on centralized location.