How can I connect to a Windows server using a Command Line Interface? (CLI)

331,249

Solution 1

There are several fairly easy options available for remotely managing a remote Windows Server using a command line, including a few native options.

Native Options:

  1. WinRS/WinRM

    • Windows Remote Shell/Management tool is the easiest way to remotely manage a remote Windows server in a command line utility, and as with most Windows command line utilities, ss64 has a good page on its options and syntax.
    • Although not explicitly stated in the Microsoft documentation, this can be used to launch a remote instance of cmd.exe, which creates an interactive command line on the remote system, rather than as command line option to execute a single command on a remote server.
      • As with: winrs -r:myserver.mydomain.tld cmd
    • This is also the natively-supported option that will probably be most familiar to administrators of other systems (*nix, BSD, etc.) that are primarily CLI-based.

  2. PowerShell

  3. Remote Desktop

    • Probably not exactly the first thing to come to mind as a Window CLI option, but of course, using mstsc.exe to connect to a server over Remote Desktop Protocl (RDP) does enable the use of a command line on the remote server.
    • Connecting to a Server Core installation over RDP, is actually possible and will give the same interface as connecting to the console - an instance of cmd.exe.

Popular, Non-Native Options:

Even though Windows now provides a few native options for accessing a remote sever over aCLI, this was not always the case, and as a result, a number of fairly popular 3rd party solutions were created. The three most notable are below.

  1. Install SSH on your Windows Server

    • If you just must have SSH, that's an option too, and there's a guide on social.technet for how to install OpenSSH on Server 2008.
    • Probably most useful for administrators of other systems (*nix, BSD, etc.) that make heavy use of SSH for this purpose, though there are advantages to even Windows-only administrators for having a single terminal emulator client (like PuTTY) store a number of target computers and customized (or standardized) settings for each.

  2. PSExec

    • The original option for executing remote commands on a Windows box through the Windows CLI, this is part of the excellent SysInternals suite. One of the very few "must have" packages for Windows admins, the SysInternals tools were so widely respected and used that SyInternals was bought out by Microsoft, and the tools are now somewhat officially supported by Microsoft.
    • Just as with WinRS/RM, PSExec can be used to issue single commands to a remote server, or to launch an interactive instance of cmd.exe on a remote computer.
      • As with: psexec \\myserver.mydomain.tld cmd
    • As with the other options, there are steps one must take first to ensure PSExec is actually able to connect to the target machine.

  3. Add a utilities folder to the server and store its value in the %PATH% system variable

    • As has been noted in the comments there are many a good SysInternals program that can be executed on the command line and targeted at a remote system, and this is true of more than just SysInternals.
    • Basically, package up a bundle of your favorite Windows utilities into a folder you push to all your servers and add that folder to the %PATH% environmental variable of your systems. Both are easily done through GPO.
    • Obviously, this is useful for more than just managing Windows systems via CLI, but I find it so useful I think it's worth including anyway.

Solution 2

Just for the sake of completeness: although it might not be the best solution for various reasons, every Windows system supports the Telnet service, which can be enabled from the features list.

Microsoft's telnet implementation also supports NTLM authentication, thus, unlike standard telnet to a Unix system, no clear-text password is sent on the network when using it.

Share:
331,249

Related videos on Youtube

HopelessN00b
Author by

HopelessN00b

Updated on September 18, 2022

Comments

  • HopelessN00b
    HopelessN00b over 1 year

    Especially with the option to install Server Core in Server 2008 and above, connecting to Windows servers over a CLI is increasingly useful ability, if not one that's very widespread amongst Windows administrators.

    Practically every Windows GUI management tool has an option to connect to a remote computer, but there is no such option present in the built-in Windows CLI (cmd.exe), which gives the initial impression that this might not be possible.

    Is it possible to remotely management or administer a Windows Server using a CLI? And if so, what options are there to achieve this?

  • John Gardeniers
    John Gardeniers over 11 years
    Don't forget the other PSTools, such as PSList, PSKill, etc. PSExec is only one small part of that toolset and most are very under utilised.
  • Joshua Drake
    Joshua Drake over 11 years
    I would also add that several command line utilities such as shutdown and iisreset (if IIS is installed) that allow one to specify a machine to execute on, and can therefore be used remotely.
  • HopelessN00b
    HopelessN00b over 11 years
    @JohnGardeniers Absolutely, and why I linked the SysInternals suite. After a couple of recent way-too-long posts, I'm trying to keep my posts more concise and to the point, though, so I didn't want to go off on any tangents like those, as great as those specific tools are for their single-uses.
  • Brent Pabst
    Brent Pabst over 11 years
    @HopelessN00b Getting there ;) I would have just listed them off, let them do the research and figure out what they all do. That's just me though. +1 for PS & RDP though, tools of the trade for sure.
  • HopelessN00b
    HopelessN00b over 11 years
    @BrentPabst Thanks for the feedback. I have a thought about how to better format this kind of thing so it does look more concise, like a list, but has some meat to it as well... I'll let it stew and preview it, maybe I'll do some editing a little later if I like the way it looks.
  • abatishchev
    abatishchev over 10 years
    Why didn't you mention Telnet Server feature?
  • HopelessN00b
    HopelessN00b over 10 years
    @abatishchev Because no one should be running a telnet server for anything in this day and age.
  • abatishchev
    abatishchev over 10 years
    Works fine to execute console commands when properly configured and run in secured environment.
  • eigenfield
    eigenfield over 5 years
    telnet server has been removed in Windows 10
  • mit
    mit over 5 years
    use this only if no other secure way is possible. the traffic should still go through a secured vpn