Jump to content

Having an issue with variables in a script.


Go to solution Solved by teksupsm,

Recommended Posts

I have a simple script that I want to run to blackhole some DNS sites (I know there are other scripts our there that do this in powershell and VB).  I am having some issues with getting it to run properly because it does not seem to be submitting my variables in the run statement.  I have highlighted the part that does not seem to work (tried both run and run(@ComSpec...

Global $domain = "somedomain.com"
Global $ipaddr = "127.0.0.1"
Global $command = "dnscmd.exe "
Global $zoneparameter = string(" /zoneadd " & $domain & " /Primary /file 000-sinkholed-domain.local.dns")
Global $ipparameter = string(" /RecordAdd " & $domain & " @ A " & $ipaddr)
Global $dns1 = "dnsserver1.local"
$domcreate1 = $command & $dns1 & $zoneparameter
$ipcreate1 = $command & $dns1 & $ipparameter

;why don't these work?
Run($domcreate1)
Run($ipcreate1)

;or these?
Run(@ComSpec & " /c " & 'dnscmd.exe ' & $zoneparameter, "", @SW_SHOW)
Run(@ComSpec & " /c " & 'dnscmd.exe ' & $ipparameter, "", @SW_SHOW)

 

Edited by teksupsm
Link to comment
Share on other sites

You are correct I was missing a " , however, the run command still does not work.  If I debug to message box it shows the following.

For the run commands....

Run($domcreate1)

Run($ipcreate1)

For the run(@ComSpec commands....

Run(@ComSpec & " /c " & 'dnscmd.exe ' & $zoneparameter, "", @SW_SHOW)

Run(@ComSpec & " /c " & 'dnscmd.exe ' & $ipparameter, "", @SW_SHOW)

Link to comment
Share on other sites

  • Solution

Found the answer....

It was the File System Redirect (2008 x64) redirecting C:\Windows\System32\ to C:WindowsSysWow64

I was able to specify in the script the working dir and now it works (see changes below)

$domain = "somedomain.com"
$ipaddr = "127.0.0.1"
$command = "dnscmd.exe "

$workingdir = 'c:windowssysnative'

$zoneparameter = string(" /zoneadd " & $domain & " /Primary /file 000-sinkholed-domain.local.dns")
$ipparameter = string(" /RecordAdd " & $domain & " @ A " & $ipaddr)
$dns1 = "dnsserver1.local"
$domcreate1 = string ($dns1 & $zoneparameter)
$ipcreate1 = string($dns1 & $ipparameter)

RunWait($workingdir&$command & $domcreate1)
RunWait($workingdir&$command & $ipcreate1)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...