Get current domain from NAnt

I use NAnt for a build and deployment tool for databases and OLAP. I wanted to be able to add only the accounts needed per-environment to certain objects on the fly through the script, as they are run on whatever workstation they are being run from.

I’m using the “Primary Dns Suffix” of the machine – which for me indicates the domain we’re running in. (Dev/Test/Prod). I’m accessing this using ipconfig /all, saving the output to text, getting the value I want as a property for use later in the script.

<exec program="ipconfig" output="ipconfig.all.txt">
    <arg value="/all" />
</exec>
<loadfile file="ipconfig.all.txt" property="ipconfig.all" />
<delete file="ipconfig.all.txt" />
<property name="envrionment" value="dev" />
<regex pattern="(?<=Primary Dns Suffixs(s.){1,7}s:s)(?<environment>w{1,})" input="${ipconfig.all}"/>
<echo message="CURRENT ENvIrONmENT: ${environment}" />

Regex Master.

Leave a Reply

Your email address will not be published. Required fields are marked *