Skip to content

Slaffcheff's place

System administration / DevOps / Life

  • About

Tag: domain

[Quicks]Useful commands when migrating to a new DC

Posted on September 29, 2015 - September 29, 2015 by Rosen Slavchev

Howdy, friends!

One of my task recently was to migrate to a new DC ‘cuz the old one is totally broken. So I had to export somehow all the users, OUs and SG from the domain controller which was so damaged that I wasn’t able to list the roles installed. That’s why I had to use PowerShell in which I’m newbie. So .. the struggle was real and I decided to share my research and knowledge related to this topic!

As I understood, the best way to export users is CSV file because this is the easiest way to import them directly to the new DC with their old profile configurations.

Get-ADUser -Filter * -Properties * | Select-Object -Property Name,SamAccountName,Description,EmailAddress,LastLogonDate,Manager,
Title,Department,whenCreated,Enabled,Organization | Sort-Object
-Property Name | ConvertTo-CSV

With this command I am telling to PowerShell to export in a CSV file all users from the Active Directory with the following parameters: Name (Rosen Slavchev), SamAccountName (rslavchev or r.slavchev or whatever your sys admin decided to be), Description (“This is test account for our ERP system and ..”), Email (rslavchev@domain.com), LastLogonDate (the format is: 10:11:12 10.11.12 y), Manager (your manager’ name set in the AD), Title (Systems Engineer), Department (Technical), whenCreated (same format as LastLogonDate), Enabled (will list only ENABLED accounts from the AD), Organization.

After all of this you can open your .csv in Excel and you will be surprised with the good result.

Another command is exporting all Organizational Unites using LDIFDE tool. The command is:

ldifde -f c:\ExportOU.ldf -s domain.local -d “dc=emeneye,dc=co,dc=local” -p subtree -r “(objectcategory=organizationalUnit)” -l “cn,objectclass,ou”

In my case I used local DC but it can be public! The format here is different. I suggest opening with editor like Notepad ++ for best review.

Analog command to this but again in .csv is:

Get-ADOrganizationalUnit -filter * | Select Name, DistinguishedName | export-csv c:\AD_OU_Tree.csv -NoTypeInformation

I hope that this was helpful for PowerShell newbies like me. Do not hesitate to ask me anything regarding this.

Posted in Quicks, Windows ServerTagged active, controller, directory, domain, export, powershell

Recent Posts

  • Segmentation fault on openSUSE Leap 15.0
  • Подпишете петицията ПРОТИВ чл. 13.
  • Free image stock and graphical resources
  • Българският mirror на openSUSE
  • openSUSE в България с 2 събитие за този месец!

Archives

  • October 2019
  • November 2018
  • June 2018
  • April 2018
  • March 2018
  • January 2018
  • October 2017
  • August 2017
  • July 2017
  • July 2016
  • September 2015
  • August 2015
  • March 2015
  • February 2015

Categories

  • Automation
  • Cyber security
  • Hacking
  • Linux
  • MySQL
  • openSUSE
  • Phrack
  • Quicks
  • Scripting
  • Uncategorized
  • Up to date
  • Web Freedom
  • Windows Server
Proudly powered by WordPress | Theme: micro, developed by DevriX.