1. Configuring, Verifying, and Removing winrm
When using Windows Remote Management (winrm) and Windows Remote Shell (winrs), both computers must be configured with winrm. The basic command to configure the computers is
You’re prompted to confirm the changes and after you do, winrm creates a winrm listener and a firewall exception.
You can view the details on the listener with the winrm enumerate command, and you can shorten enumerate to just e. The following listing shows the command and the output:
C:\>winrm e winrm/config/listener
Listener
Address = *
Transport = HTTP
Port = 80
Hostname
Enabled = true
URLPrefix = wsman
CertificateThumbprint
ListeningOn = 127.0.0.1, 192.168.1.5, ::1,
fe80::5efe:192.168.1.5%12, fe80::c065:e623:4104:1469%10
Tip
If the winrm e winrm/config/listener command doesn’t give any output, it means that the winrm listener is not installed. Execute the winrm quickconfig command to install it.
The winrm HTTP listener on port 80 listens for and acts on winrs commands that send their commands through HTTP on port 80.
If you want to delete the winrm listener, you can use the following command:
winrm invoke restore winrm/config @{}
Note
There are no spaces before or after the slash (/) in the winrm/config clause, but there is a space after config.
2. Using winrs to Issue Commands
After winrm has configured both computers, you can then use winrs to issue commands against either computer. The basic syntax is
winrs -r:server-name command
For example, if you want to enable a remote Server Core computer named SC1 to respond to pings, use this command locally on the Server Core computer:
netsh firewall set icmpsetting 8
However, you can also use this command from a remote computer:
winrs -r:sc1 netsh firewall set icmpsetting 8
The following table shows some commands you can use.
Each of these examples is run against a remote Windows Server 2008
Server Core computer named sc1 (identified in the command as -r:sc1).
Example winrs Commands | Comments |
---|
Retrieve version of remote computer.
| Shows the version of the computer. Windows Server 2008 is Microsoft Windows [Version 6.0.6001].
Windows Server 2008 R2 is Microsoft Windows [Version 6.1.7600]. |
View TCP/IP configuration.
C:\>winrs -r:sc1 ipconfig/all
| Views the TCP/IP configuration of the remote system.
|
Set address of alternate DNS server.
C:\>winrs -r:sc1 netsh
interface ipv4 add dnsserver
name="local area connection"
192.168.1.7 index=2
| You can use the netsh command to set the address of the DNS server. The alternate DNS server is configured with the add command and using an index of 2.
|
View file listing.
| Shows the file listing of all the files in the root of C on the remote system. |
Install an application.
C:\>winrs -r:sc1 msiecec.exe
/i c:\apps\app.msi /quiet
| You can use the msiexec command with the /i
switch to install a file from the command prompt. The example installs
an application named app.msi in the c:\apps folder and the /quiet switch suppresses confirmation. |
Restart the netlogon service.
C:\>winrs -r:sc1 net stop
netlogon
C:\>winrs -r:sc1 net start
netlogon
| These commands stop and restart the netlogon service, which forces the registration of SRV records.
|
List services and their state.
C:\>winrs -r:sc1 wmic service
list brief
| Lists the services on the remote computer.
Tip
You can issue any wmic commands against the remote computer.
|
Access the command prompt on a remote system.
| After executing this command, the command prompt directly interacts with the remote system. You don’t need to add winrs prefixes but instead just type the commands (such as ipconfig or ping).
Note
The prompt changes but it’s not apparent that you are on the remote
system. To double-check whether you enter commands against the local
system or the remote system, use hostname.
Tip
To exit the remote command prompt, type exit.
|