Pages

Tuesday, September 13, 2016

DiskPart : Attach a new disk and create new volume

Here are the steps required to rescan and attach a Disk on any windows server from command prompt using DiskPart utility.

  • Enter DiskPart Prompt:

C:\Windows\system32>diskpart
Microsoft DiskPart version 6.3.9600
Copyright (C) 1999-2013 Microsoft Corporation.
On computer: MyHostName

  • Perform rescan to allow DiskPart to look for any changes on the Disks attached:

DISKPART> rescan
Please wait while DiskPart scans your configuration...
DiskPart has finished scanning your configuration.

  • List Disks attached to the system:

DISKPART> list disk
  Disk ###            Status         Size                 Free     Dyn  Gpt
  --------                -------------  -------               -------  ---  ---
  Disk 0                 Online          100 GB         0 B
  Disk 1                 Offline         400 GB          400 GB

  • Select the Disk we are going to work on:

DISKPART> select disk 1
Disk 1 is now the selected disk.

  • Bring the disk online:

DISKPART> online disk
DiskPart successfully onlined the selected disk.

  • Initialize the disk:

DISKPART> attributes disk clear readonly
Disk attributes cleared successfully.

  • Create a Partition on the selected disk:

DISKPART> create partition primary
DiskPart succeeded in creating the specified partition.

  • Quick Format the newly created partition with NTFS supplying Quick parameter:

DISKPART> format fs=ntfs quick
  100 percent completed
DiskPart successfully formatted the volume.

  • List the Volumes/Partitions created and mounted on server:

DISKPART> list vol
  Volume ###      Ltr      Label                    Fs           Type                     Size        Status                  Info
  ----------              ---     -----------              -----        ----------                -------     ---------  --------
  Volume 0     D                                         DVD-ROM                          0 B         No Media
  Volume 1                     boot                     NTFS      Partition              350 MB Healthy                   System
  Volume 2     C                            Windows 201     NTFS      Partition              99 GB    Healthy                   Boot
* Volume 3                                                 NTFS      Partition              399 GB  Healthy

We want to create the Volume with Drive letter D: but since it is in use by DVD/CD Rom hence We need to change Drive Letter D: assigned to CD/DVD Rom so that it can be allocated to next partition we are going to create:

  • Select Volume number representing CD/DVD ROM drive:

DISKPART> sel vol 0
Volume 0 is the selected volume.

  • Assign a different Drive letter (Z:) to Selected Volume:

DISKPART> assign letter=z
DiskPart successfully assigned the drive letter or mount point.

Now We can assign D: to our newly created volume:
  • Select Volume number representing to the newly created volume (3 in this case):
 DISKPART> sel vol 3
Volume 3 is the selected volume.

  • Optional: We can see the details of the selected Volume:

DISKPART> det vol
  Disk ###            Status                  Size        Free    Dyn  Gpt
  --------                -------------           -------     -------  ---  ---
* Disk 1               Online                 400 GB      0 B

Read-only                          : No
Hidden                               : No
No Default Drive Letter    : No
Shadow Copy                    : No
Offline                               : No
BitLocker Encrypted         : No
Installable                          : Yes

Volume Capacity        :  399 GB
Volume Free Space      :  399 GB

  • Since the new Volume is selected now so we can change it:

DISKPART> assign letter=d
DiskPart successfully assigned the drive letter or mount point.

  • Done!
DISKPART> Exit


Tuesday, August 16, 2016

Logoff users from Remote computers


Logoff user’s active or disconnected sessions from Terminal servers
Being Windows system admins, very often we come across with situations needing to reset or logoff active or disconnected Terminal (RDP) sessions from remote Servers causing account lockouts or occupying all the allowed number of terminal server sessions.

To overcome above situations, we have to manually logoff the sessions for server(s) and to do that we either logon to the server and log off the user or do it remotely by using following commands:
Query Session /Server:ServerName
or
Query User /Server:ServerName

And then resetting the user’s session by supplying session id parameter as below:

Reset Session /Server:ServerName 5















I have written a simple batch script which does little bit of this and instead of us typing out whole command we can just put in server name and it will query remote sessions, display the output and then we need to type in session id to be reset.

Code goes below:
@echo Off
cls
echo=============================================================================
echo  This script is used to reset Terminal server Sessions from Remote server(s)
echo  causing account lockouts due to bad password or to free up Terminal Server
echo  sessions to allow new RDP connections on it.
echo.
echo  PLEASE USE WITH CAUTION, NO RESPONSIBILITY OF AUTHOR ON ANY DATA LOSS
echo  CUASED DUE TO INCORRECT/OTHER'S SESSION LOGGED OFF ACCIDENTLY:
REM Script written by Prakash Kumar (prakash82x@gmail.com) on 12:04 AM 7/25/2016
echo=============================================================================
color 0a
echo.
:Start
echo ----------------------------------------------------------------------------
Echo   Logoff active or disconnected Terminal server sessions from a server :
echo ----------------------------------------------------------------------------
echo.
set /p S=ServerName:
echo.
qwinsta /server:"%S%"
echo -----------------------------------------------------------------------------
Echo  Enter The ID to log off from above list of active/disconnected sessions:
echo -----------------------------------------------------------------------------
set /p U=SessionID:
rwinsta /server:%S% %U%
Pause
goto Start

Alternatively you can download the script from here 
Please post in the comment section below if you have any questions regarding this.
Good Luck.