Tag Archives: CLI

How to rename Windows computer using CLI

Just a quick note on renaming Windows based machine using CLI (this may be especially useful when working with Server Core).

Before renaming machine you may want to see its current name which can be achieved in three different ways:

1) ipconfig /all

Check current name - ipconfig

2) set

Check current name - set

3) hostame

Check current name - hostname

As you can see third option is best one as it gives you specifically machine name without need to search through loads of other details.

Now how to rename. You can use either NETDOM command or Rename-Computer cmdlet:

1) netdom (more details here):

netdom renamecomputer %computername% /newname:NewName /userd:domain\username /passwordd:P@ssw0rd /reboot:0

2) Rename-Computer:

Rename-Computer -NewName "NewComputerName" -Restart
Please follow and like us:
error0

Checking for Windows update presence via command line

Just a quick note on how to check if some specific Windows update is installed on the system via command prompt. I thought I already took a note of this, but was not able to find existing post on this. While investigating an issue or doing troubleshooting something more often than not you may need to make sure if some specific update is present in the system or not. And not always you may want to wade through GUI to check this. Let’s say you may want to automate this process or do some mass discovery by running script on multiple machines.

Option 1. Query WMI (Windows Management Instrumentation) namespace.

1-A. Using wmic.exe (powerful, user-friendly CLI to the WMI namespace):

wmic qfe get hotfixid | find "KB99999"

wmic qfe | find "KB99999"

1-B. Using PowerShell:

Get-WmiObject -query 'select * from win32_quickfixengineering' | foreach {$_.hotfixid}

Option 2. Using PS commandlet get-hotfix which was introduced in PS 2.0:

get-hotfix -id KB974332

So this should be enough for most of the cases.

Please follow and like us:
error0

Using PowerShell to manage network settings

Just a quick and short post on essential PowerShell cmdlets which you may use to manage network settings. The slide below taken from “Configuring and Managing Windows 8.1” module of “Preparing for Windows 8.1 MCSA” MVA course.

PoSh_Netwrork_Mgmt

To be honest I didn’t know some of cmdlets listed and those may be useful not only for MCSA exam. What especially good about the slide above it is that it match PS cmdlets with CLI commands equivalents.

Also you may look through all available commands in PS by using get-command cmdlet (do remember to pipe output into more to see less 🙂 ):

\n\n\n[code language=”powershell” light=”true”]\nget-command | more\n[/code]\n\n

And also you may use wildcard search with get-command:

\n\n\n[code language=”powershell” light=”true”]\nget-command *network*\n[/code]\n\n

Despite PS is powerful and cool way to manage things I recently tried to configure IP and other adapter settings on Server 2012 R2 core and was not very pleased with the way this can be performed with PS. GUI gives you one network adapter object to access and manage IP, DNS and all the other settings so that despite settings split in different section you have this “single point of entry” – your network adapter object. Unfortunately PS does not give us such single cmdlet which can set and change all adapter related settings – it’s all somehow dispersed/supposed to be done with different cmdlets – not very convenient 🙁

Please follow and like us:
error0

How to: do a quick check on who is connected to the server via RDP

Apart from obvious ways to do it via Windows Server GUI which is the long way (plus if you working with multiple versions like Server 2003 and 2008 it differs slightly and requires you to remember the “path” through GUI to find this information) there are CLI tool to accomplish this:

qwinsta available starting from Windows XP, if run locally lists RDP connections to local host and alternatively it can do this for remote machines (in the same domain) if run with /server key:

qwinsta /server:%SERVERNAME%

Output of this command gives you list of users connected to server along with their session ID, which you can use to disconnect sessions via command line with help of the second tool rwinsta which can be used with following syntax:

rwinsta /server:%SERVERNAME% %SESSION_ID%

Note on etimology of those commands:

qwinsta stands for Query WINdows STAntion

rwinsta stands for Reset WINdows STAntion

Starting from Windows Server 2003 you can also use query session command for the same purpose.

Please follow and like us:
error0