Search This Blog

Tuesday, May 31, 2011

Windows: Add multiple DNS servers to NIC (netSh)

Note: I have now changed the script slightly. I have added a IPCONFIG /ALL at the top, this allows me to easily review the connection name (and also copy and paste into the input field if needed).
Also I have found the address=”” parameter is not valid in versions prior to netsh in windows 2008, so now it is just addr=””
I have highlighted the changes in PURPLE in the script below.

Recently I had to configure a number of servers. I had to change the dns server IP addresses.

Now I did not want to go through all the servers 1 by 1, changing the IPs in the GUI.

Enter left, Netsh. This great little tool, allows you to configure a whole range of things within windows. But in my case I was just interested in dns servers.

First command sets the default dns server ip, then the following commands add the additional dns servers and specifies where they sit in the order via index=n.

Netsh interface ip set dns name="<connectionname>" source="static" address="x.x.x.x"

Netsh interface ip add dns name="Team 1" addr="x.x.x.x" index=2

Netsh interface ip add dns name="Team 1" addr="x.x.x.x" index=3

Netsh interface ip add dns name="Team 1" addr="x.x.x.x" index=4

Now put this into a batch file and we are laughing. Login and run, job done.

Now this does assume all servers will have a network adapter named the same thing, so I may have to change if I come across a different adapter name. mmmmm, that gets me thinking I can get round that by setting up an input into the batch file……

OK, so I did do that and here is the batch file contents. It prompts for a interface name (it has a default setting, as most of the NICs in my setup have the same name), also takes an comma separated list of dns server ip’s. The first in the server ip list will be the default dns server, and then the rest will be added in order (so the last in the list in the batch file will be the last in the dns server list).

So if you are going  to use this make sure you change the list to dns server ips and also change the defaultNIC variable to your most common NIC name.

IPCONFIG /ALL

SETLOCAL ENABLEDELAYEDEXPANSION

SET DNSServerIPaddresses=10.0.0.1,10.0.0.2,10.0.0.3,10.0.0.4
SET DefaultNIC=Nic1
SET /A Index=1

:InputNetworkAdapter
SET /p vAdapterName=Please enter network adapter name (default="%DefaultNIC%") :-

FOR %%A IN (%DNSServerIPaddresses%) DO (
    IF !Index! equ 1 (
        Netsh interface ip set dns name="%vAdapterName%" source="static" addr="%%A"
    )
    IF !Index! gtr 1 (
        Netsh interface ip add dns name="%vAdapterName%" addr="%%A" index=!Index!
    ) 
    SET /A Index=!Index!+1
)

mmm, this has got me thinking now…. with some psexec magic should be able to get this done remotely without having to connect to each machine….. O well I will save that for another day, I need to get this moving…. Smile

addition – run remotely on multiple servers.

OK, so I did use psexec and it worked a treat. I create two batch files and copied psexec into the same folder. Then I create a list of servers names, the script will prompt for a serverlist. I also created a subfolder called reports, I crate textfile of the stdout of the psexec command. the output contains a ipconfig /all berfore and after running the netsh lines, this will allow for reviewing and you can ensure that the change has held.

This script should happily work on windows 2000, 2003 and 2008 servers.

startAutoDNS.bat

:InputServerList
SET /p vserverList=Please enter filename of server list (default="serverlist.txt") :-

IF "%vserverList%"=="" (
    SET vserverList=serverlist.txt
)

FOR /F "eol=# tokens=1 delims=," %%A IN (.\%vserverList%) DO START CMD /C ".\psexec \\%%A -s -f -c autosetDNS.bat>reports\output_setDNS_%%A.txt"

autoSetDNS.bat

SETLOCAL ENABLEDELAYEDEXPANSION

IPCONFIG /ALL

SET AdapterNames=Team 1,Local Area Connection,Local Area Connection 2,Local Area Connection 3,Local Area Connection 4
REM substitute
SET AdapterNames=%AdapterNames: =/%
SET DNSServerIPaddresses=10.0.0.1,10.0.0.2,10.0.0.3,10.0.04

FOR %%B IN (%AdapterNames%) DO (
    SET /A Index=1
    SET vAdaptername=%%B
    SET vAdaptername=!vAdaptername:/= !
    FOR %%A IN (%DNSServerIPaddresses%) DO (
        IF !Index! equ 1 (
            Netsh interface ip set dns name="!vAdaptername!" source="static" addr="%%A"
        )
        IF !Index! gtr 1 (
            Netsh interface ip add dns name="!vAdaptername!" addr="%%A" index=!Index!
        )
        SET /A Index=!Index!+1
    )
)

IPCONFIG /ALL


Share/Bookmark

Tuesday, May 17, 2011

Throttle a windows network transfer (copy)

A while back I wanted to try and throttle a file copy between servers across a wan link vpn.

I struggled to find a solution to this, however in the end I came across a program from nullsoft (creators of winamp), its a freebie and was developed ages ago. However I have found the program to work extremely well.

To transfer to a network location you have to be able to map a drive to that location, and you can only copy entire folders. But for what I wanted this is fine.

You can then control bandwidth on the slider bar.

The program is called nscopy, it was available from nullsoft directly but that link appears to be gone. However I have found a download here

http://www.softpedia.com/get/System/File-Management/NSCopy.shtml

image


Share/Bookmark

Monday, May 16, 2011

PowerShell: List full path info for all files of specified extensions

I needed to get a list including path of all the files in a massive folder structure of a specified file extensions.

To do this I used PowerShell, using the Get-Childitem cmdlet to list folder content recursively and filtered to just list *.dll’s and *.exe’s. This is then piped to the foreach-object to iterate through and list the full file name (which includes path). This is then piped to the out-file cmdlet which dumps the contents into a text file.

Get-ChildItem \\remoteserver\remoteserverfolderpath  -Recurse -Include "*.dll","*.exe" | foreach-object {$_.Fullname} | Out-File c:\files.txt –width 1024


Share/Bookmark

Windows Search - Advance Query Syntax

The other day I had to try and work out how to filter files within a windows server 2008 explorer window. I knew 2008 had some good search features but had never got into using the search other than just typing in filenames or extensions with wildcards

i.e.

  • filename.*
  • *.jpg

So I started looking into AQS. There are a number of properties you can choose but I need to filter by extension and to not list folders or images. Below is the query I construction

ext: NOT (.rtf OR .doc OR .docx OR .txt OR.xls OR.msg OR .pdf OR.wps OR .xps OR .pub OR .ppt OR.odt) AND type: NOT image AND kind: NOT folders

So

ext: NOT (.rtf OR .doc OR .docx OR .txt OR.xls OR.msg OR .pdf OR.wps OR .xps OR .pub OR .ppt OR.odt)

This part will list all files with extentions

ext:

except with .rtf,.doc ,.docx,.txt,.xls,.msg,.pdf,.wpf,.xps,.pub,.ppt,.odt

NOT (.rtf OR .doc OR .docx OR .txt OR.xls OR.msg OR .pdf OR.wps OR .xps OR .pub OR .ppt OR.odt)

except  files of type image.

AND type: NOT image

except folders

AND kind: NOT folders

You can view other available properties here

http://www.microsoft.com/windows/products/winfamily/desktopsearch/technicalresources/advquery.mspx


Share/Bookmark

Monday, May 09, 2011

A DRAC 5 error has occurred–Media Active-X plugin install

Recently had this issue after getting DRAC 5 to work in Internet Explorer 9 (IE9).

Whenever going to the media page I would get offered the install, but the error would be on the page. Clicking install would drop me back to the login page for the DRAC.

I have found 2 fixes.

1. Add the IP address of the DRAC server as a site into the local intranet zone in the security tab in Internet Options.

2. For the internet zone, in security tab in internet options, select custom level and in the ActiveX controls and plug-ins Enable Automatic Prompting for ActiveX Controls.


Share/Bookmark

Logmein.com and Internet Explorer 9: No ActiveX install option

Recently I had installed Internet Explorer 9. When I then tried to connect to Logmein Remote computers, I was presented with the Install ActiveX page, however I got no prompt.

I tried a number of things to get it to install, but to no avail and I would have to click on the link for no install option.

However a few weeks later I had an issue where I could not connect to my DRAC controllers. The solution I found for this seems to have fixed the issue I had with Logmein.

See the article for more info.

But in essence I reset Internet Explorer to factory defaults. (Goto internet options, advanced tab and click reset).

In addition I cleared out temporary files, objects and files to to try and ensure every thing was clean.

logmein.com was still in my trusted sites in IE (this seems to have not been cleared out).

On returning to logmein, I was presented with the install ActiveX page after a small wait I was presented with the prompt to install, which I did. Now when going to remote computers I am not presented with the install page.


Share/Bookmark

Dell Remote Access Controller (DRAC) and IE: “The XML page cannot be displayed”

I recently had issue connecting to my DRAC 5 controllers from Internet Explorer 9 (IE9).

The problem manifested itself as the above error message, and in some cases only the IP address and Port were displayed on the web page.

After searching the internet it appears that various people have had this issue since IE7.

The fix was pretty simple, but I must warn you it means resetting IE back to its default settings, so I have no idea what impact this will have if you have customised the IE config.

In IE9 internet options goto the advanced tab and press reset in the “Reset Internet Explorer Settings” section.

This stage was not necessary but I thought I would just try and take it back to a clea state.

I also cleared out the temporary internet files and objects. In addition I deleted all history, cookies etc….


Share/Bookmark