Kaseya Community

netsh not working as expected in script

  • I'm trying to get an export of the DHCP settings on a server. I'm using the following command in a script;

     

    netsh dhcp server export c:\path_to_file all

     

    This works on the command line on the server. However when used in a sript it returns;

     

    The following command was not found: dhcp server export c:\path_to_file all

     

    The same thing happens if I run it as an Execute File command and point it at the absolute location of the netsh.exe and use the other bits as parameters.

     

    Anyone else seen this ? Any ideas how I can resolve it?

    Olly

  • You're going to have to impersonate before you run the netsh.  Some netsh options are not available when ran as the SYSTEM user.

  • This is what I use:

    netsh dhcp server #vMachine.IpAddress# dump>>#vAgentConfiguration.agentTempDir#\DHCP.txt

  • hi Smason,

    Would that DHCP.TXT file still be able to be used to import the settings back in to the DHCP server in the event of **** ups though? I thought only the export file could be used by the import process.

  • You wouldn't use the import command. I think it would be "netsh exec DHCP.txt"

    Source #1: support.microsoft.com/.../325473

    "Note The export option does not exist in the netsh command on Windows 2000 Server. The netsh dhcp server dump and netsh dhcp server import commands are not compatible. You can migrate the exported configuration file to the new Windows Server 2003 server by using the following command: netsh exec c:\dhcp.txt"

    Source #2: technet.microsoft.com/.../cc787375(WS.10).aspx

    "This command dumps the DHCP configuration as text output within the command prompt window. You can copy or redirect this output to a file to view it in a text editor. After file output is obtained, you can use the exec command to configure another DHCP server with the same configuration."