Deploying Windows Server 2012 DC using Powershell

at 6/22/2015
Hey guys,
In this short article I want to show you how to install Windows Server 2012 Domain Controllers and Forests by using the new Powershell cmdlets provided with this Edition. Server 2012 introduced a lot of new features and it has introduced a new way to install and configure Domain Controllers. Installing a new machine using the interface it's still pretty intuitive so instead, I'll insist in showing you how to achieve this by using Powershell. Before we can use the new cmdlets to configure our DC, execute the following command to install AD Domain Services:
Install-windowsfeature -name AD-Domain-Services –IncludeManagementTools

To explore newly introduced cmdlets, type in the following:
Get-Command -Module ADDSDeployment
Powershell Domain Controller deployment

There are two situations that can occur when deploying a new Domain Controller:
  • Deploying a DC in a new Forest
Before we can go at the installation part, we'll need to make sure our new forest will pass the needed requirements. Use the Test-ADDSForestInstallation cmdlet to test the forest installation:

Test-ADDSForestInstallation -DomainName "" -NoRebootOnCompletion

Powershell create new Active Directory Forest

If the operation is completed successfully you can proceed further with the forest installation.
When adding the first Domain Controller to a new Forest, you will need to execute the following:

 -CreateDnsDelegation:$false `
 -DatabasePath "C:\Windows\NTDS" `
 -DomainMode "Win2012R2" `
 -DomainName "" `
 -DomainNetbiosName "" `
 -ForestMode "Win2012R2" `
 -InstallDns:$true `
 -LogPath "C:\Windows\NTDS" `
 -NoRebootOnCompletion:$false `
 -SysvolPath "C:\Windows\SYSVOL" `

You will be prompted to set a DSRM password for the specified forest. Note that the operation will take some time so be patience. The first Domain Controller within a Forest will also be a Global Catalog server.
  • Deploying a DC in an existing Domain
To test weather your forest supports adding the machine as a Domain Controller for your existing Farm, use the following cmdlet:
Test-ADDSDomainControllerInstallation -InstallDns -Credential (Get-Credential
PPSCU\Administrator) -DomainName ""

Once all tests have been completed successfully, execute the following command to add your new DC. Note that you'll have to change the parameters values according to your needs:

Import-Module ADDSDeployment
Install-ADDSDomainController '
-NoGlobalCatalog:$false '
-CreateDnsDelegation:$false '
-Credential (Get-Credential) '
-CriticalReplicationOnly:$false '
-DatabasePath "C:\Windows\NTDS" '
-DomainName "" '
-InstallDns:$true '
-LogPath "C:\Windows\NTDS" '
-NoRebootOnCompletion:$false '
-SiteName "" '
-SysvolPath "C:\Windows\SYSVOL" '

To uninstall a DC from a domain, use the Test-ADDSDomainControllerUninstallation and Uninstall-ADDSDomainController cmdlets.
That's about it for this article folks, hope you will enjoy it. Have a great day!

Configuring NXlog with python

at 6/15/2015
Hello folks,
I've finally started working with python for one of our new automatization systems, saltstack. I've been experimenting with saltstack recently so I don't have much experience in this technology. Anyway, I've created a script that allows you to configure a log aggregation server (such as Graylog or Flume) on your NXlog client. The script verifies if a hostname or IP address is already configured using a regex formula and if a configuration is not found, allows you to configure the server:

import re
import logging
import subprocess

logger = logging.getLogger(__name__)

def checkconf():
    k = 0
    file = 'C:\\Program Files (x86)\\nxlog\\conf\\nxlog.conf'
    for line in f:
        if re.match("^\s*Host\s*([a-z]|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})", line):
            k = 1
    if k == 1:
        return True
        return False

def set(flumeip=""):
    configfile = 'C:\\Program Files (x86)\\nxlog\\conf\\nxlog.conf'
    oldpattern = "Host "
    newpattern = "Host " + flumeip

    if checkconf() == True:"Nxlog configuration already found, skipping")
        f = open(configfile,'r')
        filedata =
        newdata = filedata.replace(oldpattern,newpattern)
        f = open(configfile,'w')
        f.close()'net stop "nxlog"')"NXlog service Stopped")'net start "nxlog"')"NXlog service Started")"IP configured for the NXlog client")
        return True

checkconf() function verifies if the server is already configured and returns either True or False if a match is found or not.
set() function checks the returned value of checkconf() and then either skips the configuration if a match is found or adds the IP/hostname and then restarts the NXlog service.
That's about all for this article, if you have any misunderstandings don't hesitate to post a comment in my dedicated section. 

Error when trying to install Windows Server 2012 on VirtualBox

at 5/28/2015
I've discovered lately an error on VirtualBox when trying to install Windows Server 2012 on one virtual machine. It seems that VirtualBox encounters an error when trying to boot the OS from the image file. The error reported is "Your PC needs to restart, Please hold down the power button":
VirtualBox error

I've tried restarting both VirtualBox and my PC and the problem still persists. After searching a bit on the internet, I've found the solution by executing VBoxManage setextradata [vmname] VBoxInternal/CPUM/CMPXCHG16B 1 from Powershell. First, you will need to navigate to the location of the VBoxManage tool (C:\Program Files\Oracle\VirtualBox) and then execute the command above. Note that the vmname must be replaced with the actual name of the virtual machine:
Windows Server 2012 error

Now you should be able to successfully install Microsoft Windows Server 2012