d

WSH WMI Set/Enable Static IP

setHostIp( "win2k", "0", "10.37.4.1", "255.255.0.0" );
setHostIp( "win2k", "1", "10.37.4.2", "255.255.0.0" );


function setHostIp( Server, Nic, IP, Subnet )
{
    try
    {
        print( "Attempting to set ip on " + Server );
        var ip     = String( IP );
        var subnet = Subnet;
        var server = Server;
        var nic    = Nic;
        
        print( "connecting to server" );
        var connect = "winmgmts:{impersonationLevel=impersonate}!\\\\" + 
                      server + "\\root\\cimv2:Win32_NetworkAdapterConfiguration.Index=\"" + nic + "\"";
        
        var adapter = GetObject( connect );
        
        var rst = 0;
        print( "Enabling IP Address" );
        adapter.EnableStatic( ip, subnet );
        if( rst == 0 )
        {
            print( "Successfully set " + server + "'s IP Address to " + ip );
        }
        else
        {
            print( "Failed to set ip address on " + server );
        }
        print( "Complete" );
    }
    catch( e )
    {
        print( "Error: " + e.description );
    }
}

function print( msg )
{
    WScript.Echo( msg );
}