Sunday, 21 June 2015

Creating Bulk AD Users in Active Directory using Powershell in Windows server 2008

Before proceed, please ensure that the Active Directory module for Windows Powershell is installed or not in your machine. It will be installed by default in Domain Controller. In client machines, you need to install it through Remote Server Administration Tools.
  
Use below command to check Active Directory module is installed or not:

Get-Module -Listavailable
If you are newbie to Powershell, don’t forget to set your Execution Policy to unrestricted or you might get an error when you try run the script. Use the below command to set your Execution Policy: 

Set-ExecutionPolicy Unrestricted


Powershell Script to Create Bulk AD Users from CSV file

1) Consider the CSV file ADUserscreation.csv which contains set of New AD Users to create with the attributes Name,samAccountName and etc.

2) Copy the below Powershell script and paste in Notepad file.
3) Change the ADUserscreation.csv file path with your own csv file path.
4) Change the domain name test.com into your own domain name
5) SaveAs the Notepad file with the extension .ps1 like USERCREATION.ps1

$objOU=[ADSI]“LDAP://OU=Internal,DC=test,DC=com”
$dataSource=import-csv “ADUserCreation.csv”
foreach($dataRecord in $datasource) {
$cn=$dataRecord.FirstName + ” ” + $dataRecord.LastName
$email=$dataRecord.Email
$description=$dataRecord.EmpID
$address=$dataRecord.UserAddress
$company=$dataRecord.CompanyName
$department=$dataRecord.UserDepartment
$physicalDeliveryOfficeName=$dataRecord.OfficeDetail
$title=$dataRecord.JobTitle
$telephoneNumber=$dataRecord.UserTelephoneNumber
$mobile=$dataRecord.UserMobile
$sAMAccountName=$dataRecord.SAM
$givenName=$dataRecord.FirstName
$sn=$dataRecord.LastName
$sAMAccountName=$sAMAccountName.ToLower()
$displayName=$givenName + ” ” + $sn
$userPrincipalName=$sAMAccountName + “@test.com”
$objUser=$objOU.Create(“user”,”CN=”+$cn)
$objUser.Put(“sAMAccountName”,$sAMAccountName)
$objUser.Put(“userPrincipalName”,$userPrincipalName)
$objUser.Put(“displayName”,$displayName)
$objUser.Put(“givenName”,$givenName)
$objUser.Put(“sn”,$sn)
$objUser.Put("mail",$email)
$objUser.Put("description",$description)
$objUser.Put("mobile",$mobile)
$objUser.Put("streetAddress",$address)
$objUser.Put("company",$company)
$objUser.Put("department",$department)
$objUser.Put("physicalDeliveryOfficeName",$physicalDeliveryOfficeName)
$objUser.Put("title",$title)
$objUser.Put("telephoneNumber",$telephoneNumber)
$objUser.SetInfo()
$objUser.SetPassword(“Test@123”)
$objUser.pwdLastSet = 0
$objUser.psbase.InvokeSet(“AccountDisabled”,$false)
$objUser.SetInfo()
}


6) Now run the USERCREATION.ps1 file in Powershell to create Bulk Active Directory users from CSV file. 
PSC:\Scripts> .\USERCREATION.ps1
Note: I have placed script file in the location C:\Scripts, if you placed in any other location, you can navigate to that path using CD path command (like cd "C:\Downloads").

7) Now you can check the newly Created AD Users though ADUC console.

Device eth0 does not seem to be present, delaying initialisation in linux

However if you clone a VMWare you’ll notice that it kills your network interfaces throwing errors like the one listed below:

#ifup eth0
Device eth0 does not seem to be present, delaying initialisation

What’s happening here is that when you clone your VM, VMWare apply a new MAC Address to your network interfaces but they don’t update the linux configuration files to mirror these changes and so the kernel doesn’t firstly can’t find or start the interface that matches it’s configuration (with the old MAC Address) and it finds a new interface (the new MAC Address) that it has no configuration information for. The result is that only your networking service can only start the loopback networking interface and eth0 is dead.

So here’s how we fix it:

Remove the kernel’s networking interface rules file so that it can be regenerated

# rm -f /etc/udev/rules.d/70-persistent-net.rules

Restart the VM
# reboot

UPDATE your interface configuration file
# vim /etc/sysconfig/networking/devices/ifcfg-eth0
Remove the MACADDR entry or update it to the new MACADDR for the interface (listed in this file: /etc/udev/rules.d/70-persistent-net.rules).

Remove the UUID entry

Save and exit the file

Restart the networking service
# service network restart

The user profile service: Service failed the log on. User profile can not be loaded - Windows

Find the below steps.

1, Copy C:\users\default folder(Hiden) on the workstation which has no problem to somewhere (i.e. desktop) and rename it to default2.

2, Copy default2 folder to C:\users\ on the workstation which has a problem.

3, go to registory (regedit) HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\Default and change the pass to %SystemDrive%\User\Default2.

4, Reboot the workstation.

Problem "Another MySQL daemon already running with the same unix socket"

To prevent the problem from occurring, you must perform a graceful shutdown of the server from the command line rather than powering off the server.

# shutdown -h now

This will stop the running services before powering down the machine.

Based on Centos, an additional method for getting it back up again when you run into this problem is to move mysql.sock:

# mv /var/lib/mysql/mysql.sock /var/lib/mysql/mysql.sock.bak

# service mysqld start

Restarting the service creates a new entry called mqsql.sock

Erase RAID metadata from (previously used) disk.

Find the below simple steps.


  • If your disk has RAID metadata that it is impossible to erase with common ways but you'd like to erase it to use the disk with no RAID. 


  • Then attach the disk to another mashine that Linux is installed and boot it first. 


  • Next erase RAID metadata with the following way.


[1]Install mdadm to verify disks.
[root@test ~]# 
yum -y install mdadm dmraid

[2]If your disk has RAID metadata, following result is shown. 
The example below, it shows there is RAID metadata at 124914352 sector on /dev/sdb.

[root@test ~]# 
dmraid -r 

/dev/sdb: ddf1, ".ddf1_disks", GROUP, ok, 124914352 sectors, data@ 0

[3]Erase RAID metadata with mdadm like follows.

[root@test ~]# 
mdadm --zero-superblock /dev/sdb 

[root@test ~]# 
dmraid -r 

no raid disks and with names: "/dev/sdb"


[4]If it's impossible to erase with the way of [3], 
overwrite with dd command like follows.

[root@test ~]# 
dd if=/dev/zero of=/dev/sdb bs=512 seek=124914352 

[root@test ~]# 
dmraid -r 

no raid disks and with names: "/dev/sdb"

How to disable "Set as Desktop Background" as an option in Firefox using Group Policy

Find the below simple steps.

1) To create file userChrome.css with below mentioned contents.

/*
* Edit this file and copy it as userChrome.css into your
* profile-directory/chrome/
*/


/*
* This file can be used to customize the look of Mozilla's user interface
* You should consider using !important on rules which you want to
* override default settings.
*/

/*
* Do not remove the @namespace line -- it's required for correct functioning
*/

@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); /* set default namespace to XUL */
#context-setDesktopBackground {display: none !important;}
/* Tools > Clear Recent History - hide */
#sanitizeItem { display: none !important }

/* Tools > Options > Privacy - hide clear recent history options */
#clearDataBox { display: none !important }

/* Remove Sidebar History Searchbox */
#history-panel > hbox {display:none !important;}

/* Remove Organize bookmarks */
#bookmarksShowAll {display:none !important;}

/* Remove Items from History Menu */
menupopup > menuitem[label="Home"] {display:none !important;}
menupopup > menuitem[label="Show All History"] {display:none !important;}
menupopup > menuitem[label="Back"] {display:none !important;}
menupopup > menuitem[label="Forward"] {display:none !important;}
menupopup > menu[label="Recently Closed Tabs"] {display:none !important;}
menupopup > menu[label="Recently Closed Windows"] {display:none !important;}
menupopup > menuseparator[id="startHistorySeparator"] {display:none !important;}
menupopup > menuseparator[id="endHistorySeparator"] {display:none !important;}

/*
* Some possible accessibility enhancements:
*/

/*
* Make all the default font sizes 20 pt:
*
* * {
* font-size: 20pt !important
* }
*/
/*

* Give the Location (URL) Bar a fixed-width font
*
* #urlbar {
* font-family: monospace !important;
* }
*/
/*
* For more examples see http://www.mozilla.org/unix/customizing.html
*/

2) userChrome.css file should be saved in domain share drive.

3) Then Create batch file with below mentioned contents.

set folder=%APPDATA%\Mozilla\Firefox\Profiles

if exist "%APPDATA%\Mozilla\Firefox" for /D %%F in ("%APPDATA%\Mozilla\Firefox\Profiles\*") do Xcopy /E \\share path\* %%F

4) Deploy this batch files via Group Policy. A very common way of doing so is User Logon scripts.