Restart Windows Services from Linux

If you use Linux, and you need to restart a Windows service, you don’t need to logon to a Windows machine.

You just need to run the following commands:

net rpc service stop SERVICENAME -I IPADDRESS -U USERNAME%PASSWORD
and
net rpc service start SERVICENAME -I IPADDRESS -U USERNAME%PASSWORD
If you don’t know the Service name, you can list the available services with:
net rpc service list -I IPADDRESS -U USERNAME%PASSWORD
Just a little head’s up. You will need the samba-common package installed in your Linux box.

Quickly open a program in administrator mode in Windows 7

We all need to use the “Run As Administrator” option in Windows 7, Vista or Server 2008, at some point.

The obvious way is to right click and select the “Run As Administrator” option, but, there’s another way.

Use the shortcut Ctrl + Shift + Click to open any software in administrator mode.

 

Verify replication with other domain controllers

When you need to test your domain replication, you can run a couple of tests from the command line.

To verify replication is functioning

  1. Open a Command Prompt.
  2. Type dcdiag /test:replication and press Enter.
  3. To verify that the proper permissions are set for replication, type dcdiag /test:netlogonsand then press Enter.Messages indicate if the connectivity and netlogons tests passed.

Active Directory – Identify FSMO Role holders

Sometimes you need to know who’s who you in your Active Directory. What domain controller is responsible for what.

In that case, all you need to do is to run a very useful command.

Open a command line on a domain controller and type:

netdom query fsmo

This will give you the FSMO role owners for the domain controller domain.

If you have a scenario of several domain in a forest, and you want to query a specific domain, you can add the /domain parameter.

netdom query /domain:domainname.TLD fsmo

 

Cleanup Windows devices

Hello reader.

 

We all know that Windows stores a lot of information about devices we plug-in. That might lead to performance problems and even device connectivity issues.

But how do we get rid of that friend’s USB drive that we plugged-in once to copy some pictures.

How about a server recently virtualized, showing you network warnings when setting up the static IP address?

Reinstall the system? No.

Here’s how:

 

Open a command line (use Administrator mode in Vista/7/Server 2008) and type:

set devmgr_show_nonpresent_devices=1

and then type:

devmgmt.msc

After that, just select the option “Show Hidden Devices” under the View menu.

And you can see all the devices no longer available in your computer.

You just have to select the device, one by one, and uninstall it.

Note: The command line should be open during the whole process.

 

 

Active Directory replication fails Event ID 1265

If you get the Event ID 1265 from NTDS KCC in your Domain Controller Event Viewer or you get the error: “The naming context is in the process of being removed or is not replicated from the specified server.” when replicating from Active Directory Sites and Services, that is caused by a missing SRV record in your DNS.
To fix this issue just there a couple of simple steps.
1. Open a CMD prompt.

2. ping <YourDomainController>.<YourDomain.com>. If the PING could NOT find the host, the DNS database does NOT have a SRV resource record for <YourDomainController>.<YourDomain.com>.

3. Open Administrative Tools / DNS and expand the DNS server.

4. Expand Forward Lookup Zones.

5. Right-click each zone and press Properties.

6. Set Allow dynamic updates to Yes or Only secure updates.

7. Press OK.

8. Open a CMD prompt on your DNS server and type net stop dns followed by net start dns.

9. Open a CMD prompt on your <YourDomainController> and type net stop netlogon followed by net start netlogon.

Delete Failed DCs from Active Directory

S#!” Happens!!!
The hardware failed, some software installation killed you DC or you just formatted it without demoting it first.
This will leave the entries in you Active Directory database and will eventually give you some trouble.
So, to remove this information all you need is to open a command line and be a member of the Enterprise Admins universal group.
So, open a command line and type ntdsutil. This will give you a new prompt.
At the ntdsutil: prompt, type metadata cleanup and press Enter.
At the metadata cleanup: prompt, type connections and press Enter.
At the server connections: prompt, type connect to server <servername>, where <servername> is the domain controller (any functional domain controller in the domain) from which you plan to clean up the metadata of the failed domain controller. Press Enter.
Type quit and press Enter to return you to the metadata cleanup: prompt.
Type select operation target and press Enter.
Type list domains and press Enter. This lists all domains in the forest with a number associated with each.
Type select domain <number>, where <number> is the number corresponding to the domain in which the failed server was located. Press Enter.
Type list sites and press Enter.
Type select site <number>, where <number> refers to the number of the site in which the domain controller was a member. Press Enter.
Type list servers in site and press Enter. This will list all servers in that site with a corresponding number.
Type select server <number> and press Enter, where <number> refers to the domain controller to be removed.
Type quit and press Enter. The Metadata cleanup menu is displayed.
Type remove selected server and press Enter.

You will receive a warning message. Read it, and if you agree, press Yes.

At this point, Active Directory confirms that the domain controller was removed successfully. If you receive an error that the object could not be found, Active Directory might have already removed from the domain controller.

Type quit, and press Enter until you return to the command prompt.

After you just need to confirm if the object was completely removed from Active Directory.

To remove the failed server object from the sites

In Active Directory Sites and Services, expand the appropriate site.

If the object exists, delete the server object associated with the failed domain controller, then open Active Directory Users and Computers go to the Domain Controllers container and, again, if exists, delete the computer object associated with the failed domain controller

You might get a warning asking you if you want to delete the server object without performing a DCPROMO operation (which, of course, you cannot perform). Just select “This DC is permanently offline…” and click on the Delete button.AD will display another confirmation window. If you’re sure that you want to delete the failed object, click Yes.

All that’s missing now is the DNS entries. So open the DNS mmc console.

In the DNS snap-in, expand the zone that is related to the domain from where the server has been removed.
Remove the CNAME record in the _msdcs.root domain of forest zone in DNS. You should also delete the HOSTNAME and other DNS records.
If you have reverse lookup zones, also remove the server from these zones.
Just a couple of word of advice.
Using the ntdsutil utility incorrectly may result in partial or complete loss of Active Directory functionality.
If the Domain Controller was responsible for any FSMO, don’t forget to seize the roles first.

Reset the DSRM Administrator Password

Let’s say your new at some organization and you need to be sure of the Directory Services Restore Mode password.

Here’s how:

Open a command line and type ntdsutil.

At the Ntdsutil command prompt, type set dsrm password.

At the DSRM command prompt, type one of the following lines:

To reset the password on the server on which you are working, type reset password on server null. The null variable assumes that the DSRM password is being reset on the local computer. Type the new password when you are prompted. Note that no characters appear while you type the password.

-or-

To reset the password for another server, type reset password on server servername, where servername is the DNS name for the server on which you are resetting the DSRM password. Type the new password when you are prompted. Note that no characters appear while you type the password.

When your done, just quit by typing q at the DSRM command prompt, and then at the ntdsutil command prompt.

How to Back Up and Restore SQL Server Logins

Backing Up and Restoring Logins

You can back up and restore logins using a script as described in the following procedures.

To back up a login using a script (SQL Server 2005 or SQL Server 2008)
  1. Start SQL Server Management Studio.
  2. Expand the Security folder, and then expand the list of Logins.
  3. Right-click the login you want to create a backup script for, and then select Script Login as.
  4. Click CREATE To, and then click one of New Query Editor WindowFile, or Clipboard to select a destination for the script. Typically, the destination is a file with a .sql extension.
  5. Repeat this procedure from Step 3 for each login you want to script.
To restore a login from a script (SQL Server 2005 or SQL Server 2008)
  1. Start SQL Server Management Studio.
  2. Click File, click Open, and then click File.
  3. Locate and open the file containing the scripted login.
  4. Execute the script to create the login.

What’s up SQL – Number 2 – SQL Server Version

Hello reader.

 

Did you ever had to look up for the SQL Server version you are using?

Me too. Here’s how I do it.

 

Open a new query in SQL Server Management Studio and type:

SELECT @@VERSION
GO
The result will be something like this:
“Microsoft SQL Server 2008 R2 (SP1) – 10.50.2500.0 (X64)   Jun 17 2011 00:54:03   Copyright (c) Microsoft Corporation  Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) “
If you need more information you can also use the Stored Procedure sp_server_info, to get information like system collation.