Common commands and tasks to make dealing with Windows Core easier.

2

January 20, 2020 by Kenneth Fisher

I don’t know how many of you are working with Windows Core these days but personally I think it’s a pretty cool concept. You aren’t supposed to be logging into your servers all that often so why have the extra overhead of Windows? Windows Core removes all of that and comes back with something that looks and feels remarkably like DOS from when I started with computers. That said, most of us, myself included, aren’t used to just having DOS commands any more so here are some helpful tips. I should point out that there is actually more than just DOS commands available and I’ll go over a bit of that here as well.

DOS/CMD

Unlike the original DOS machines you can actually open multiple DOS windows. Technically they are actually CMD windows, just FYI. You can also create multiple Powershell windows.

Here is a list of common DOS/CMD commands. I’ve also got a post here where I go over a bunch of things useful in batch files, some of which you might find useful here too.

Some of my favorites (see the above link for details and more commands):

  • cd – change directory
  • cls – clear screen
  • copy – copy file(s)
  • del – delete file(s)
  • dir – directory listing
  • find – find a string in a file
  • help – available commands (<– Important command here folks)
  • md (mkdir) – make a folder (directory)
  • more – displays a file’s contents (paginated) (space bar to page, enter for a single line)
  • move – move a file
  • ping – test connection to another host
  • rd (rmdir) – remove a folder (directory)
  • ren – rename file(s)
  • type – displays a file’s contents (no pagination)
  • Save output from a DOS command to a file: > (overwrite) or >> (append)
    For example:
    DIR > MyDir.txt
    DIR >> MyDir.txt

 


Some other handy CMD/PoSH commands

CMD

  • List drives: fsutil fsinfo drives
  • List drive size and free space: fsutil volume diskfree C:
  • List services: sc query
  • Show all mounted disks: wmic logicaldisk list brief
  • Name of the current server: hostname
  • Display environment variables: set

 
PoSH

  • List drives: Get-PSDrive
  • Show all mounted disks: Get-Volume
  • Name of the current server: hostname
  • Display environment variables: set
  • Show the date/time: Get-Date
  • Show installed Features: Get-WindowsFeature
  • Add Windows Feature: Add-WindowsFeature
  • Run PoSH as an administrator: Start-Process -FilePath “powershell” -Verb runAs
  • Show services Get-Service | sort-object
  • List drives, sizes and free space (replace server name):
    Get-WMIObject Win32_Logicaldisk -filter "" |
    Select PSComputername,DeviceID,
    @{Name="SizeGB";Expression={$_.Size/1GB -as [int]}},
    @{Name="FreeGB";Expression={[math]::Round($_.Freespace/1GB,2)}}
  • Show drive size, letter, volume name, partition:
    Get-WmiObject Win32_DiskDrive | % {
      $disk = $_
      $partitions = "ASSOCIATORS OF " +
                    "{Win32_DiskDrive.DeviceID='$($disk.DeviceID)'} " +
                    "WHERE AssocClass = Win32_DiskDriveToDiskPartition"
      Get-WmiObject -Query $partitions | % {
        $partition = $_
        $drives = "ASSOCIATORS OF " +
                  "{Win32_DiskPartition.DeviceID='$($partition.DeviceID)'} " +
                  "WHERE AssocClass = Win32_LogicalDiskToPartition"
        Get-WmiObject -Query $drives | % {
          New-Object -Type PSCustomObject -Property @{
            Disk        = $disk.DeviceID
            DiskSize    = $disk.Size
            DiskModel   = $disk.Model
            Partition   = $partition.Name
            RawSize     = $partition.Size
            DriveLetter = $_.DeviceID
            VolumeName  = $_.VolumeName
            Size        = $_.Size
            FreeSpace   = $_.FreeSpace
          }}}}

 


Net commands

I don’t know much about the net command but here are some handy uses:

  • Dealing with shared folders (really handy if you need to copy files back and forth from another location): (Note: Powershell command included where I know it.)
    • List shares:
      NET SHARE
      Get-SmbShare
    • New share:
      NET SHARE MyShare=E:\ /grant:domain\user,full
      New-SmbShare -Name “MyShare” -Path “E:\” -FullAccess “domain\user”
    • Remove a share:
      NET SHARE MyShare /DELETE
      Remove-SmbShare -Name “MyShare”
  • Create, modify or remove Windows users and groups
    • NET USER “NewUser” “NewPassword” /ADD
    • NET USER “NewUser” /DELETE
    • NET LOCALGROUP “NewGroup” /ADD
    • NET LOCALGROUP “NewGroup” /DELETE
    • etc.
  • Same command as above but here’s how you view members of the administrators group, or add/remove people from that group.
    • NET LOCALGROUP administrators
      Get-LocalGroupMember -Group administrators
    • NET LOCALGROUP administrators “NewUser” /ADD
      Add-LocalGroupMember -Group Administrators -Member NewUser
    • NET LOCALGROUP administrators “NewUser” /DELETE
      Remove-LocalGroupMember -Group Administrators -Member NewUser

 


Run Powershell/CMD remotely.

Powershell
If your current id doesn’t have permissions on the remote machine then right click on Powershell and select Run as different user. Otherwise just open Powershell. Run the following code, replacing XXX with the computer name.

Enter-PSsession -computername XXX

CMD
Same instructions as above but with a CMD shell.

winrs -r:XXX cmd

 


Common tools still available
  • Task Manager: tskmgr (or Ctrl-Alt-End and use arrow keys)
  • Registry editor: regedit
  • Notepad: notepad
  • msinfo32: msinfo32
  • Windows Explorer: (Sort of) open Notepad or msinfo32 and go to file open.

 


Help! I’ve closed all of my CMD windows!

You can also hit CTRL-ALT-END (the same as hitting CTRL-ALT-DEL on your local machine) and select Task Manager. Then go to File->Run New Task. Once a prompt comes up type CMD and a new command shell will come up.
 


Logging off

To log off of the machine you have to use the logoff command. You can also hit CTRL-ALT-END and select Sign Out. Do not use exit as it will close the current CMD window and not log you out. If for some reason you close out the window and need to open a new one see above.

2 thoughts on “Common commands and tasks to make dealing with Windows Core easier.

  1. […] Kenneth Fisher takes us through some helpful commands when working with Windows Server (particularly…: […]

  2. Kris S. says:

    You can also run Task Manager using Ctrl+Shift+Esc keyboard shortcut

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 3,148 other followers

Follow me on Twitter

ToadWorld Pro of the Month November 2013
%d bloggers like this: