---
title: "How To Connect A EBS Volume To An Windows EC2 Instance Using Powershell/GUI"
lang: "en"
author: "Mohammad Abu Mattar"
canonical: https://mkabumattar.com/post/how-to-connect-a-ebs-volume-to-an-windows-ec2-instance-using-powershell-gui
---

![Blog post image for How To Connect A EBS Volume To An Windows EC2 Instance Using Powershell/GUI - In this post, we will learn how to connect an EBS volume to a Windows EC2 instance using PowerShell or the Disk Management GUI.](/_astro/hero.CPGBv147_2dVKbI.webp)

[Home](/)›[Blog](/blog)›[All Categories](/blog/categories)›[AWS](/blog/categories/aws)

Blog

[Prev in AWSHow to CI/CD AWS With Github using Jenkins](/blog/post/how-to-ci-cd-aws-with-github-using-jenkins)[Next in AWSHow To Connect A Two EC2 Instances Data Transfer Using AWS CLI Without AWS EFS](/blog/post/how-to-connect-a-two-ec2-instances-data-transfer-using-aws-cli-without-aws-efs)

[AWS](/blog/categories/aws)[Windows Server](/blog/categories/windows-server)[EC2](/blog/categories/ec2)[EBS](/blog/categories/ebs)[PowerShell](/blog/categories/powershell)

# How To Connect A EBS Volume To An Windows EC2 Instance Using Powershell/GUI

[Mohammad Abu Mattar](/authors/mohammad-abu-mattar)Published: 15 Nov 202211 Mins read19 Mins listen

[Markdown for AI(opens in a new tab)](/post/how-to-connect-a-ebs-volume-to-an-windows-ec2-instance-using-powershell-gui/index.md "Open the plain-Markdown version of this page, for pasting into an AI tool")

TL;DR

In this post, we will learn how to connect an EBS volume to a Windows EC2 instance using PowerShell or the Disk Management GUI.

Series

[AWS Automation](/series/aws-automation)5/6

[PreviousHow to Connect to AWS RDS MySQL Database to EC2 Instance With PHP By Using PDO](/blog/post/how-to-connect-to-aws-rds-mysql-database-to-ec2-instance-with-php-by-using-pdo)[NextScaling Up, Staying Strong: Hands-On AWS CloudFormation Techniques for Building Resilient and Scalable Systems](/blog/post/scaling-up-staying-strong-hands-on-aws-cloudformation-techniques-for-building-resilient-and-scalable-systems)

All posts in this series (6)

Blog6

1.  [How to Run an Apache Web Server Using Docker on an AWS EC2 Instance](/blog/post/how-to-run-an-apache-web-server-using-docker-on-an-aws-ec2-instance)
2.  [How to Create a AWS RDS MySQL Database and Connect to it using MySQL Workbench](/blog/post/how-to-create-a-aws-rds-mysql-database-and-connect-to-it-using-mysql-workbench)
3.  [How to Install and Configure Node.js on EC2 Instance Amazon Linux 2](/blog/post/how-to-install-and-configure-nodejs-on-ec2-instance-amazon-linux-2)
4.  [How to Connect to AWS RDS MySQL Database to EC2 Instance With PHP By Using PDO](/blog/post/how-to-connect-to-aws-rds-mysql-database-to-ec2-instance-with-php-by-using-pdo)
5.  [How To Connect A EBS Volume To An Windows EC2 Instance Using Powershell/GUIYou are here](/blog/post/how-to-connect-a-ebs-volume-to-an-windows-ec2-instance-using-powershell-gui)
6.  [Scaling Up, Staying Strong: Hands-On AWS CloudFormation Techniques for Building Resilient and Scalable Systems](/blog/post/scaling-up-staying-strong-hands-on-aws-cloudformation-techniques-for-building-resilient-and-scalable-systems)

### How To Connect A EBS Volume To An Windows EC2 Instance Using Powershell/GUI

Contents

[Introduction](#introduction)[Prerequisites](#prerequisites)[Create a VPC](#create-a-vpc)[Step 1: create a VPC](#step-1-create-a-vpc)[Step 2: modify your custom VPC and enable DNS hostname support and DNS support](#step-2-modify-your-custom-vpc-and-enable-dns-hostname-support-and-dns-support)[Step 3: create a public subnet](#step-3-create-a-public-subnet)[Step 4: enable auto-assign public IP on the subnet](#step-4-enable-auto-assign-public-ip-on-the-subnet)[Step 5: create an Internet Gateway](#step-5-create-an-internet-gateway)[Step 6: attach the Internet Gateway to the VPC](#step-6-attach-the-internet-gateway-to-the-vpc)[Step 7: create a route table](#step-7-create-a-route-table)[Step 8: create a custom route table association](#step-8-create-a-custom-route-table-association)[Step 9: associate the subnet with the route table, making it a public subnet](#step-9-associate-the-subnet-with-the-route-table-making-it-a-public-subnet)[Step 10: create a security group](#step-10-create-a-security-group)[Step 11: Add a rule to the security group](#step-11-add-a-rule-to-the-security-group)[Create a Windows Server 2022 EC2 instance](#create-a-windows-server-2022-ec2-instance)[Step 1: get the latest AMI ID](#step-1-get-the-latest-ami-id)[Step 2: create a key pair](#step-2-create-a-key-pair)[Step 3: create an EC2 instance](#step-3-create-an-ec2-instance)[Step 4: wait for the EC2 instance to be running](#step-4-wait-for-the-ec2-instance-to-be-running)[Step 5: get the public IP address of the EC2 instance](#step-5-get-the-public-ip-address-of-the-ec2-instance)[Create an EBS volume](#create-an-ebs-volume)[Step 1: create an EBS volume](#step-1-create-an-ebs-volume)[Step 2: wait for the EBS volume to be available](#step-2-wait-for-the-ebs-volume-to-be-available)[Attach the EBS volume to the EC2 instance](#attach-the-ebs-volume-to-the-ec2-instance)[Step 1: attach the EBS volume to the Windows Server EC2 instance](#step-1-attach-the-ebs-volume-to-the-windows-server-ec2-instance)[Step 2: wait for the EBS volume to be in-use](#step-2-wait-for-the-ebs-volume-to-be-in-use)[Connect to the Windows Server EC2 instance](#connect-to-the-windows-server-ec2-instance)[Step 1: connect to the Windows Server EC2 instance using RDP (Remote Desktop Protocol) in Linux](#step-1-connect-to-the-windows-server-ec2-instance-using-rdp-remote-desktop-protocol-in-linux)[\# Step 1.1: create a new RDP connection](#-step-11-create-a-new-rdp-connection)[\# Step 1.2: connect to the Windows Server EC2 instance](#-step-12-connect-to-the-windows-server-ec2-instance)[Step 2: connect to the Windows Server EC2 instance using RDP (Remote Desktop Protocol) in Windows](#step-2-connect-to-the-windows-server-ec2-instance-using-rdp-remote-desktop-protocol-in-windows)[\# Step 2.1: create a new RDP connection](#-step-21-create-a-new-rdp-connection)[\# Step 2.2: connect to the Windows Server EC2 instance](#-step-22-connect-to-the-windows-server-ec2-instance)[Connect to the EBS volume](#connect-to-the-ebs-volume)[Connect to the EBS volume using PowerShell](#connect-to-the-ebs-volume-using-powershell)[\# Step 1: partition and format the volume with DiskPart](#-step-1-partition-and-format-the-volume-with-diskpart)[\# Step 2: check the EBS volume](#-step-2-check-the-ebs-volume)[Connect to the EBS volume using Disk Management](#connect-to-the-ebs-volume-using-disk-management)[\# Step 1: bring the disk online and create a volume](#-step-1-bring-the-disk-online-and-create-a-volume)[\# Step 2: check the EBS volume using Disk Management](#-step-2-check-the-ebs-volume-using-disk-management)[Conclusion](#conclusion)[References](#references)

## [Introduction](#introduction)

In this post, we will learn how to connect an EBS volume to a Windows EC2 instance using PowerShell or the Disk Management GUI, and how to mount the volume on the instance.

## [Prerequisites](#prerequisites)

-   AWS CLI installed and configured
-   IAM user with the following permissions:
    -   AmazonVPCFullAccess
    -   AmazonEC2FullAccess
    -   AmazonElasticBlockStoreFullAccess

## [Create a VPC](#create-a-vpc)

### [Step 1: create a VPC](#step-1-create-a-vpc)

To create a VPC, run the following command:

Terminal window

```
1# Create a VPC2AWS_VPC=$(aws ec2 create-vpc \3  --cidr-block 10.0.0.0/16 \4  --query 'Vpc.VpcId' \5  --output text)6
7# Add a name tag to the VPC8aws ec2 create-tags \9  --resources $AWS_VPC \10  --tags Key=Name,Value=aws-vpc
```

Explanation:

-   `aws ec2 create-vpc` - Create a VPC
-   `--cidr-block` - The IPv4 network range for the VPC, in CIDR notation.
-   `--query` - The JMESPath query that is applied to the output.
-   `--output` - The output format of the command.
-   `--resources` - The IDs of the resources.
-   `--tags` - The tags to apply to the resource.

### [Step 2: modify your custom VPC and enable DNS hostname support and DNS support](#step-2-modify-your-custom-vpc-and-enable-dns-hostname-support-and-dns-support)

To modify your custom VPC and enable DNS hostname support and DNS support, run the following command:

Terminal window

```
1# Enable DNS hostnames2aws ec2 modify-vpc-attribute \3  --vpc-id $AWS_VPC \4  --enable-dns-hostnames "{\"Value\":true}"5
6# Enable DNS support7aws ec2 modify-vpc-attribute \8  --vpc-id $AWS_VPC \9  --enable-dns-support "{\"Value\":true}"
```

Explanation:

-   `aws ec2 modify-vpc-attribute` - Modifies the specified attribute of the specified VPC.
-   `--vpc-id` - The ID of the VPC.
-   `--enable-dns-hostnames` - Indicates whether the instances launched in the VPC get DNS hostnames.
-   `--enable-dns-support` - Indicates whether DNS resolution is supported for the VPC.

### [Step 3: create a public subnet](#step-3-create-a-public-subnet)

To create a public subnet, run the following command:

Terminal window

```
1# Create a public subnet2AWS_PUBLIC_SUBNET=$(aws ec2 create-subnet \3  --vpc-id $AWS_VPC \4  --cidr-block 10.0.1.0/24 \5  --query 'Subnet.SubnetId' \6  --output text)7
8# Add a name tag to the public subnet9aws ec2 create-tags \10  --resources $AWS_PUBLIC_SUBNET \11  --tags Key=Name,Value=aws-public-subnet
```

Explanation:

-   `aws ec2 create-subnet` - Creates a subnet in an existing VPC.
-   `--vpc-id` - The ID of the VPC.
-   `--cidr-block` - The IPv4 network range for the subnet, in CIDR notation.
-   `--query` - The JMESPath query that is applied to the output.
-   `--output` - The output format of the command.
-   `--resources` - The IDs of the resources.
-   `--tags` - The tags to apply to the resource.

### [Step 4: enable auto-assign public IP on the subnet](#step-4-enable-auto-assign-public-ip-on-the-subnet)

To enable auto-assign public IP on the subnet, run the following command:

Terminal window

```
1# Enable auto-assign public IP on the subnet2aws ec2 modify-subnet-attribute \3  --subnet-id $AWS_PUBLIC_SUBNET \4  --map-public-ip-on-launch
```

Explanation:

-   `aws ec2 modify-subnet-attribute` - Modifies a subnet attribute.
-   `--subnet-id` - The ID of the subnet.
-   `--map-public-ip-on-launch` - Specify true to indicate that network interfaces created in the specified subnet should be assigned a public IPv4 address.

### [Step 5: create an Internet Gateway](#step-5-create-an-internet-gateway)

To create an Internet Gateway, run the following command:

Terminal window

```
1# Create an Internet Gateway2AWS_INTERNET_GATEWAY=$(aws ec2 create-internet-gateway \3  --query 'InternetGateway.InternetGatewayId' \4  --output text)5
6# Add a name tag to the Internet Gateway7aws ec2 create-tags \8  --resources $AWS_INTERNET_GATEWAY \9  --tags Key=Name,Value=aws-internet-gateway
```

Explanation:

-   `aws ec2 create-internet-gateway` - Creates an Internet gateway for use with a VPC.
-   `--query` - The JMESPath query that is applied to the output.
-   `--output` - The output format of the command.
-   `--resources` - The IDs of the resources.
-   `--tags` - The tags to apply to the resource.

### [Step 6: attach the Internet Gateway to the VPC](#step-6-attach-the-internet-gateway-to-the-vpc)

To attach the Internet Gateway to the VPC, run the following command:

Terminal window

```
1# Attach the Internet Gateway to the VPC2aws ec2 attach-internet-gateway \3  --internet-gateway-id $AWS_INTERNET_GATEWAY \4  --vpc-id $AWS_VPC
```

Explanation:

-   `aws ec2 attach-internet-gateway` - Attaches an Internet gateway to a VPC, enabling connectivity between the Internet and the VPC.
-   `--internet-gateway-id` - The ID of the Internet gateway.
-   `--vpc-id` - The ID of the VPC.

### [Step 7: create a route table](#step-7-create-a-route-table)

To create a route table, run the following command:

Terminal window

```
1# Create a route table2AWS_ROUTE_TABLE=$(aws ec2 create-route-table \3  --vpc-id $AWS_VPC \4  --query 'RouteTable.RouteTableId' \5  --output text)6
7# Add a name tag to the route table8aws ec2 create-tags \9  --resources $AWS_ROUTE_TABLE \10  --tags Key=Name,Value=aws-route-table
```

Explanation:

-   `aws ec2 create-route-table` - Creates a route table for the specified VPC.
-   `--vpc-id` - The ID of the VPC.
-   `--query` - The JMESPath query that is applied to the output.
-   `--output` - The output format of the command.
-   `--resources` - The IDs of the resources.
-   `--tags` - The tags to apply to the resource.

### [Step 8: create a custom route table association](#step-8-create-a-custom-route-table-association)

To create a custom route table association, run the following command:

Terminal window

```
1# Create a custom route table association2aws ec2 associate-route-table \3  --subnet-id $AWS_PUBLIC_SUBNET \4  --route-table-id $AWS_ROUTE_TABLE
```

Explanation:

-   `aws ec2 associate-route-table` - Associates a subnet with a route table.
-   `--subnet-id` - The ID of the subnet.
-   `--route-table-id` - The ID of the route table.

### [Step 9: associate the subnet with the route table, making it a public subnet](#step-9-associate-the-subnet-with-the-route-table-making-it-a-public-subnet)

To associate the subnet with the route table, making it a public subnet, run the following command:

Terminal window

```
1# Associate the subnet with route table, making it a public subnet2aws ec2 create-route \3  --route-table-id $AWS_ROUTE_TABLE \4  --destination-cidr-block 0.0.0.0/0 \5  --gateway-id $AWS_INTERNET_GATEWAY
```

Explanation:

-   `aws ec2 create-route` - Creates a route in a route table within a VPC.
-   `--route-table-id` - The ID of the route table for the route.
-   `--destination-cidr-block` - The IPv4 CIDR address block used for the destination match.
-   `--gateway-id` - The ID of an Internet gateway or virtual private gateway attached to your VPC.

### [Step 10: create a security group](#step-10-create-a-security-group)

To create a security group, run the following command:

Terminal window

```
1# Create a security group2AWS_SECURITY_GROUP=$(aws ec2 create-security-group \3  --group-name aws-security-group \4  --description "AWS Security Group" \5  --vpc-id $AWS_VPC \6  --query 'GroupId' \7  --output text)8
9# Add a name tag to the security group10aws ec2 create-tags \11  --resources $AWS_SECURITY_GROUP \12  --tags Key=Name,Value=aws-security-group
```

Explanation:

-   `aws ec2 create-security-group` - Creates a security group.
-   `--group-name` - The name of the security group.
-   `--description` - A description for the security group.
-   `--vpc-id` - The ID of the VPC.
-   `--query` - The JMESPath query that is applied to the output.
-   `--output` - The output format of the command.
-   `--resources` - The IDs of the resources.
-   `--tags` - The tags to apply to the resource.

### [Step 11: Add a rule to the security group](#step-11-add-a-rule-to-the-security-group)

To add a rule to the security group, run the following command:

Terminal window

```
1# Add a rule to the security group2
3# Allow RDP >> remote desktop protocol4aws ec2 authorize-security-group-ingress \5  --group-id $AWS_SECURITY_GROUP \6  --protocol tcp \7  --port 3389 \8  --cidr 0.0.0.0/0 \9  --output text10
11# Add HTTP rule12aws ec2 authorize-security-group-ingress \13  --group-id $AWS_SECURITY_GROUP \14  --protocol tcp \15  --port 80 \16  --cidr 0.0.0.0/0 \17  --output text18
19# Add HTTPS rule20aws ec2 authorize-security-group-ingress \21  --group-id $AWS_SECURITY_GROUP \22  --protocol tcp \23  --port 443 \24  --cidr 0.0.0.0/0 \25  --output text
```

Explanation:

-   `aws ec2 authorize-security-group-ingress` - Adds one or more ingress rules to a security group.
-   `--group-id` - The ID of the security group.
-   `--protocol` - The IP protocol name or number.
-   `--port` - The port number.
-   `--cidr` - The IPv4 CIDR range.
-   `--output` - The output format of the command.

## [Create a Windows Server 2022 EC2 instance](#create-a-windows-server-2022-ec2-instance)

### [Step 1: get the latest AMI ID](#step-1-get-the-latest-ami-id)

To get the latest AMI ID, run the following command:

Terminal window

```
1# Get the latest AMI ID2AWS_AMI=$(aws ec2 describe-images \3  --owners 'amazon' \4  --filters 'Name=name,Values=amzn2-ami-hvm-2.0.*' \5  'Name=state,Values=available' \6  --query 'sort_by(Images, &CreationDate)[-1].[ImageId]' \7  --output 'text')
```

Explanation:

-   `aws ec2 describe-images` - Describes one or more of the images (AMIs, AKIs, and ARIs) available to you. Images available to you include public images, private images that you own, and private images owned by other AWS accounts but for which you have explicit launch permissions.
-   `--owners` - Filters the images by the owner. Specify an AWS account ID, `self` (owner is the sender of the request), or an AWS owner alias (valid values are `amazon`, `aws-marketplace`, `microsoft`).
-   `--filters` - One or more filters. Use a filter to return a more specific list of results.
-   `--query` - The JMESPath query that is applied to the output.
-   `--output` - The output format of the command.

### [Step 2: create a key pair](#step-2-create-a-key-pair)

To create a key pair, run the following command:

Terminal window

```
1# Create a key pair2aws ec2 create-key-pair \3  --key-name aws-key-pair \4  --query 'KeyMaterial' \5  --output text > aws-key-pair.pem6
7# Change the permissions of the key pair8chmod 400 aws-key-pair.pem
```

Explanation:

-   `aws ec2 create-key-pair` - Creates a 2048-bit RSA key pair with the specified name. Amazon EC2 stores the public key and displays the private key for you to save to a file. The private key is returned as an unencrypted PEM encoded PKCS#8 private key. If a key with the specified name already exists, Amazon EC2 returns an error.
-   `--key-name` - The name for your key pair.
-   `--query` - The JMESPath query that is applied to the output.
-   `--output` - The output format of the command.

Note

The private key, which is returned as an unencrypted PEM encoded PKCS#8 private key, is only returned if you have access to the key pair. You must provide the corresponding key pair file when you launch an instance.

Note

You will use this key pair to decrypt the administrator password in the AWS EC2 console.

### [Step 3: create an EC2 instance](#step-3-create-an-ec2-instance)

To create an EC2 instance, run the following command:

Terminal window

```
1# Create an EC2 instance2AWS_INSTANCE=$(aws ec2 run-instances \3  --image-id $AWS_AMI \4  --instance-type t2.micro \5  --key-name aws-key-pair \6  --monitoring "Enabled=false" \7  --security-group-ids $AWS_SECURITY_GROUP \8  --subnet-id $AWS_PUBLIC_SUBNET \9  --query 'Instances[0].InstanceId' \10  --output text)11
12# Add a name tag to the EC2 instance13aws ec2 create-tags \14  --resources $AWS_INSTANCE \15  --tags Key=Name,Value=aws-instance-windows
```

Explanation:

-   `aws ec2 run-instances` - Launches the specified number of instances using an AMI for which you have permissions.
-   `--image-id` - The ID of the AMI.
-   `--instance-type` - The instance type.
-   `--key-name` - The name of the key pair.
-   `--monitoring` - Enables detailed monitoring (disabled by default).
-   `--security-group-ids` - The IDs of the security groups.
-   `--subnet-id` - The ID of the subnet in which to launch the instance.
-   `--query` - The JMESPath query that is applied to the output.
-   `--output` - The output format of the command.

### [Step 4: wait for the EC2 instance to be running](#step-4-wait-for-the-ec2-instance-to-be-running)

To wait for the EC2 instance to be running, run the following command:

Terminal window

```
1# Wait for the EC2 instance to be running2aws ec2 wait instance-running \3  --instance-ids $AWS_INSTANCE
```

Explanation:

-   `aws ec2 wait instance-running` - Wait until an instance is running.
-   `--instance-ids` - The IDs of the instances.

### [Step 5: get the public IP address of the EC2 instance](#step-5-get-the-public-ip-address-of-the-ec2-instance)

To get the public IP address of the EC2 instance, run the following command:

Terminal window

```
1# Get the public IP address of the EC2 instance2AWS_PUBLIC_IP=$(aws ec2 describe-instances \3  --instance-ids $AWS_INSTANCE \4  --query 'Reservations[0].Instances[0].PublicIpAddress' \5  --output text)
```

Explanation:

-   `aws ec2 describe-instances` - Describes one or more of your instances.
-   `--instance-ids` - The IDs of the instances.
-   `--query` - The JMESPath query that is applied to the output.
-   `--output` - The output format of the command.

## [Create an EBS volume](#create-an-ebs-volume)

### [Step 1: create an EBS volume](#step-1-create-an-ebs-volume)

To create an EBS volume, run the following command:

Terminal window

```
1# Get the availability zone for the EC2 instance2AWS_AVAILABILITY_ZONE=$(aws ec2 describe-instances \3  --instance-ids $AWS_INSTANCE \4  --query 'Reservations[0].Instances[0].Placement.AvailabilityZone' \5  --output text)6
7# Create an EBS volume8AWS_VOLUME=$(aws ec2 create-volume \9  --availability-zone $AWS_AVAILABILITY_ZONE \10  --size 10 \11  --volume-type gp2 \12  --query 'VolumeId' \13  --output text)14
15# Add a name tag to the EBS volume16aws ec2 create-tags \17  --resources $AWS_VOLUME \18  --tags Key=Name,Value=aws-volume
```

Explanation:

-   `aws ec2 describe-instances` - Describes one or more of your instances.
-   `--instance-ids` - The IDs of the instances.
-   `--query` - The JMESPath query that is applied to the output.
-   `--output` - The output format of the command.
-   `aws ec2 create-volume` - Creates an EBS volume that can be attached to an instance in the same Availability Zone.
-   `--availability-zone` - The Availability Zone in which to create the volume.
-   `--size` - The size of the volume, in GiBs.
-   `--volume-type` - The volume type.
-   `--query` - The JMESPath query that is applied to the output.
-   `--output` - The output format of the command.

Note

Availability zone for the EC2 instance and EBS volume must be the same. Otherwise, you will get the following error: `InvalidParameterValue: The requested Availability Zone is currently constrained and only m3.medium or m3.large instances can be launched.`

### [Step 2: wait for the EBS volume to be available](#step-2-wait-for-the-ebs-volume-to-be-available)

To wait for the EBS volume to be available, run the following command:

Terminal window

```
1# Wait for the EBS volume to be available2aws ec2 wait volume-available \3  --volume-ids $AWS_VOLUME
```

Explanation:

-   `aws ec2 wait volume-available` - Wait until a volume is in the available state.
-   `--volume-ids` - The IDs of the volumes.

## [Attach the EBS volume to the EC2 instance](#attach-the-ebs-volume-to-the-ec2-instance)

### [Step 1: attach the EBS volume to the Windows Server EC2 instance](#step-1-attach-the-ebs-volume-to-the-windows-server-ec2-instance)

To attach the EBS volume to the Windows Server EC2 instance, run the following command:

Terminal window

```
1# Attach the EBS volume to the Windows Server EC2 instance2aws ec2 attach-volume \3  --device xvdf \4  --instance-id $AWS_INSTANCE \5  --volume-id $AWS_VOLUME
```

Explanation:

-   `aws ec2 attach-volume` - Attaches an EBS volume to a running or stopped instance and exposes it to the instance with the specified device name.
-   `--device` - The device name (for example, /dev/sdh or xvdh).
-   `--instance-id` - The ID of the instance.
-   `--volume-id` - The ID of the EBS volume.

### [Step 2: wait for the EBS volume to be in-use](#step-2-wait-for-the-ebs-volume-to-be-in-use)

To wait for the EBS volume to be in-use, run the following command:

Terminal window

```
1# Wait for the EBS volume to be in-use2aws ec2 wait volume-in-use \3  --volume-ids $AWS_VOLUME
```

Explanation:

-   `aws ec2 wait volume-in-use` - Wait until a volume is in the in-use state.
-   `--volume-ids` - The IDs of the volumes.

## [Connect to the Windows Server EC2 instance](#connect-to-the-windows-server-ec2-instance)

### [Step 1: connect to the Windows Server EC2 instance using RDP (Remote Desktop Protocol) in Linux](#step-1-connect-to-the-windows-server-ec2-instance-using-rdp-remote-desktop-protocol-in-linux)

If you are on Linux, you can connect to the Windows Server EC2 instance over RDP (Remote Desktop Protocol). To do so, you need to install the `remmina` package. To install the `remmina` package, run the following command:

Terminal window

```
1# Install the remmina package2
3# Arch Linux4sudo pacman -S remmina5
6# Debian/Ubuntu7sudo apt install remmina -y8
9# CentOS/RHEL10sudo yum install remmina -y11
12# Fedora13sudo dnf install remmina -y14
15# OpenSUSE16sudo zypper install remmina -y
```

Explanation:

-   `pacman` - Arch Linux package manager.
-   `apt` - Debian/Ubuntu package manager.
-   `yum` - CentOS/RHEL package manager.
-   `dnf` - Fedora package manager.
-   `zypper` - OpenSUSE package manager.

#### [Step 1.1: create a new RDP connection](#step-11-create-a-new-rdp-connection)

-   Click on the `+` button to add a new connection.
-   Enter the following details:
    -   `Name` - Enter a name for the connection.
    -   `Protocol` - Select `RDP`.
    -   `Server` - Enter the public IP address of the Windows Server EC2 instance.
    -   `Username` - Enter the username of the Windows Server EC2 instance.
    -   `Password` - Enter the password of the Windows Server EC2 instance.
-   Click on the `Save` button.

Note

To get the password of the Windows Server EC2 instance, run the following command:

Terminal window

```
1# Get the password of the Windows Server EC2 instance2EC2_INSTANCE_PASSWORD=$(aws ec2 get-password-data \3  --instance-id $AWS_INSTANCE \4  --priv-launch-key aws-key-pair.pem \5  --query 'PasswordData' \6  --output text)7
8# Desplay the password of the Windows Server EC2 instance9echo $EC2_INSTANCE_PASSWORD
```

Explanation:

-   `aws ec2 get-password-data` - Retrieves the encrypted administrator password for the instances running Windows.
-   `--instance-id` - The ID of the instance.
-   `--priv-launch-key` - The private key that is required to decrypt the password data.
-   `--query` - The JMESPath query that is applied to the output.
-   `--output` - The output format of the command.

![remmina](/assets/blog/0027-how-to-connect-a-ebs-volume-to-an-windows-ec2-instance-using-powershell-gui/remmina.png)

#### [Step 1.2: connect to the Windows Server EC2 instance](#step-12-connect-to-the-windows-server-ec2-instance)

-   Click on the `Connect` button to connect to the Windows Server EC2 instance.

![Connect to the Windows Server EC2 Instance](/assets/blog/0027-how-to-connect-a-ebs-volume-to-an-windows-ec2-instance-using-powershell-gui/connect-to-the-windows-server-ec2-instance.png)

### [Step 2: connect to the Windows Server EC2 instance using RDP (Remote Desktop Protocol) in Windows](#step-2-connect-to-the-windows-server-ec2-instance-using-rdp-remote-desktop-protocol-in-windows)

If you are on Windows, you can connect to the Windows Server EC2 instance over RDP (Remote Desktop Protocol). To do so, you need to install the `Microsoft Remote Desktop` app. To install the `Microsoft Remote Desktop` app, run the following command:

Terminal window

```
1# Install the Microsoft Remote Desktop app2winget install Microsoft.RemoteDesktop
```

Explanation:

-   `winget` - Windows package manager.

#### [Step 2.1: create a new RDP connection](#step-21-create-a-new-rdp-connection)

-   Click on the `+` button to add a new connection.
-   Enter the following details:
    -   `Name` - Enter a name for the connection.
    -   `Computer` - Enter the public IP address of the Windows Server EC2 instance.
    -   `Username` - Enter the username of the Windows Server EC2 instance.
    -   `Password` - Enter the password of the Windows Server EC2 instance.

Note

To get the password of the Windows Server EC2 instance, run the following command:

Terminal window

```
1# Get the password of the Windows Server EC2 instance2EC2_INSTANCE_PASSWORD=$(aws ec2 get-password-data \3  --instance-id $AWS_INSTANCE \4  --priv-launch-key aws-key-pair.pem \5  --query 'PasswordData' \6  --output text)7
8# Desplay the password of the Windows Server EC2 instance9echo $EC2_INSTANCE_PASSWORD
```

Explanation:

-   `aws ec2 get-password-data` - Retrieves the encrypted administrator password for the instances running Windows.
-   `--instance-id` - The ID of the instance.
-   `--priv-launch-key` - The private key that is required to decrypt the password data.
-   `--query` - The JMESPath query that is applied to the output.
-   `--output` - The output format of the command.

![Microsoft Remote Desktop](/assets/blog/0027-how-to-connect-a-ebs-volume-to-an-windows-ec2-instance-using-powershell-gui/microsoft-remote-desktop.png)

#### [Step 2.2: connect to the Windows Server EC2 instance](#step-22-connect-to-the-windows-server-ec2-instance)

-   Click on the `Connect` button to connect to the Windows Server EC2 instance.

![Connect to the Windows Server EC2 Instance](/assets/blog/0027-how-to-connect-a-ebs-volume-to-an-windows-ec2-instance-using-powershell-gui/connect-to-the-windows-server-ec2-instance-windows.png)

## [Connect to the EBS volume](#connect-to-the-ebs-volume)

### [Connect to the EBS volume using PowerShell](#connect-to-the-ebs-volume-using-powershell)

#### [Step 1: partition and format the volume with DiskPart](#step-1-partition-and-format-the-volume-with-diskpart)

-   Open the `PowerShell` app.
-   Run the following command to connect to the EBS volume:

Terminal window

```
1# Connect to diskpart2diskpart3
4# List the disks5list disk6
7# Select the disk8select disk 19
10# initialize the disk11convert gpt12
13# Create a new partition14create partition primary15
16# List the partitions17list partition18
19# Select the partition20select partition 221
22# Assign a drive letter23assign letter=D24
25# Format the partition26format fs=ntfs quick27
28# Exit diskpart29exit
```

Explanation:

-   `diskpart` - DiskPart is a command-line tool that you can use to manage disks and volumes.
-   `list disk` - Lists all disks on the computer.
-   `select disk` - Selects a disk for use.
-   `convert gpt` - Converts a disk to the GPT partition style.
-   `create partition primary` - Creates a primary partition on the selected disk.
-   `list partition` - Lists all partitions on the selected disk.
-   `select partition` - Selects a partition for use.
-   `assign letter` - Assigns a drive letter to the selected partition.
-   `format fs=ntfs quick` - Formats the selected partition.
-   `exit` - Exits DiskPart.

![Connect to the EBS Volume using PowerShell](/assets/blog/0027-how-to-connect-a-ebs-volume-to-an-windows-ec2-instance-using-powershell-gui/connect-to-the-ebs-volume-using-powershell.png)

#### [Step 2: check the EBS volume](#step-2-check-the-ebs-volume)

-   Run the following command to check the EBS volume:

Terminal window

```
1# List the disks2Get-Partition | Get-Volume
```

Explanation:

-   `Get-Partition` - Gets the partitions on a disk.
-   `Get-Volume` - Gets the volumes on a disk.

![Check the EBS Volume](/assets/blog/0027-how-to-connect-a-ebs-volume-to-an-windows-ec2-instance-using-powershell-gui/check-the-ebs-volume.png)

### [Connect to the EBS volume using Disk Management](#connect-to-the-ebs-volume-using-disk-management)

#### [Step 1: bring the disk online and create a volume](#step-1-bring-the-disk-online-and-create-a-volume)

-   Open the Search bar by pressing the `Windows` key + `S`.
-   Type `diskmgmt.msc` and press `Enter`.
-   Right-click on the `Disk 1` and click on the `Online` option.
-   Right-click on the `Disk 1` and click on the `Initialize Disk` option.
-   Right-click on the `Unallocated` space and click on the `New Simple Volume` option.
-   Click on the `Next` button.
-   Click on the `Next` button.
-   Click on the `Next` button.
-   Click on the `Finish` button.

![Connect to the EBS Volume using Disk Management](/assets/blog/0027-how-to-connect-a-ebs-volume-to-an-windows-ec2-instance-using-powershell-gui/connect-to-the-ebs-volume-using-disk-management.png)

#### [Step 2: check the EBS volume using Disk Management](#step-2-check-the-ebs-volume-using-disk-management)

-   Right-click on the `Disk 1` and click on the `Properties` option.
-   Click on the `Volumes` tab.
-   Click on the `D:` drive.

![Check the EBS Volume](/assets/blog/0027-how-to-connect-a-ebs-volume-to-an-windows-ec2-instance-using-powershell-gui/check-the-ebs-volume-using-disk-management.png)

## [Conclusion](#conclusion)

In this tutorial, we learned how to connect an EBS volume to a Windows EC2 instance, using either PowerShell or the Disk Management GUI.

## [References](#references)

-   [Amazon EC2 User Guide for Windows Instances](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/concepts.html)
-   [Amazon EBS volumes](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-volumes.html)
-   [Attach an Amazon EBS volume to an instance](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-attaching-volume.html)
-   [Make an Amazon EBS volume available for use on Windows](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ebs-using-volumes.html)
-   [AWS Command Line Interface (CLI) User Guide](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html)
-   [AWS CLI Command Reference - ec2](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ec2/index.html)
-   [Amazon VPC User Guide](https://docs.aws.amazon.com/vpc/latest/userguide/what-is-amazon-vpc.html)
-   [AWS Identity and Access Management (IAM) User Guide](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html)
-   [Connect to your Windows instance using RDP](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/connecting_to_windows_instance.html)
-   [DiskPart command-line options (Microsoft Docs)](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/diskpart)
-   [Initialize new disks (Microsoft Docs)](https://learn.microsoft.com/en-us/windows-server/storage/disk-management/initialize-new-disks)
-   [PowerShell Get-Disk cmdlet](https://learn.microsoft.com/en-us/powershell/module/storage/get-disk)
-   [PowerShell Initialize-Disk cmdlet](https://learn.microsoft.com/en-us/powershell/module/storage/initialize-disk)
-   [PowerShell New-Partition cmdlet](https://learn.microsoft.com/en-us/powershell/module/storage/new-partition)
-   [PowerShell Format-Volume cmdlet](https://learn.microsoft.com/en-us/powershell/module/storage/format-volume)

Was this useful?

## Tags

[#AWS EBS](/blog/tags/aws-ebs)[#Windows EC2](/blog/tags/windows-ec2)[#Attach EBS Volume](/blog/tags/attach-ebs-volume)[#PowerShell Disk Management](/blog/tags/powershell-disk-management)[#AWS CLI](/blog/tags/aws-cli)[#AWS VPC](/blog/tags/aws-vpc)[#RDP](/blog/tags/rdp)[#DiskPart](/blog/tags/diskpart)

## Share

[Facebook](https://facebook.com/sharer/sharer.php?u=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-connect-a-ebs-volume-to-an-windows-ec2-instance-using-powershell-gui "Share on Facebook")[Twitter](https://twitter.com/intent/tweet/?text=How%20To%20Connect%20A%20EBS%20Volume%20To%20An%20Windows%20EC2%20Instance%20Using%20Powershell%2FGUI&url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-connect-a-ebs-volume-to-an-windows-ec2-instance-using-powershell-gui "Share on Twitter")[LinkedIn](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-connect-a-ebs-volume-to-an-windows-ec2-instance-using-powershell-gui&title=How%20To%20Connect%20A%20EBS%20Volume%20To%20An%20Windows%20EC2%20Instance%20Using%20Powershell%2FGUI&summary=In%20this%20post%2C%20we%20will%20learn%20how%20to%20connect%20an%20EBS%20volume%20to%20a%20Windows%20EC2%20instance%20using%20PowerShell%20or%20the%20Disk%20Management%20GUI.&source=https://mkabumattar.com "Share on LinkedIn")[WhatsApp](https://wa.me/?text=How%20To%20Connect%20A%20EBS%20Volume%20To%20An%20Windows%20EC2%20Instance%20Using%20Powershell%2FGUI%20https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-connect-a-ebs-volume-to-an-windows-ec2-instance-using-powershell-gui "Share on WhatsApp")[Telegram](https://t.me/share/url?url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-connect-a-ebs-volume-to-an-windows-ec2-instance-using-powershell-gui&text=How%20To%20Connect%20A%20EBS%20Volume%20To%20An%20Windows%20EC2%20Instance%20Using%20Powershell%2FGUI "Share on Telegram")[Reddit](https://www.reddit.com/submit?url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-connect-a-ebs-volume-to-an-windows-ec2-instance-using-powershell-gui&title=How%20To%20Connect%20A%20EBS%20Volume%20To%20An%20Windows%20EC2%20Instance%20Using%20Powershell%2FGUI "Share on Reddit")[Hacker News](http://news.ycombinator.com/submitlink?u=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-connect-a-ebs-volume-to-an-windows-ec2-instance-using-powershell-gui&t=How%20To%20Connect%20A%20EBS%20Volume%20To%20An%20Windows%20EC2%20Instance%20Using%20Powershell%2FGUI "Share on Hacker News")[Pinterest](https://pinterest.com/pin/create/button/?url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-connect-a-ebs-volume-to-an-windows-ec2-instance-using-powershell-gui&media=&description=In%20this%20post%2C%20we%20will%20learn%20how%20to%20connect%20an%20EBS%20volume%20to%20a%20Windows%20EC2%20instance%20using%20PowerShell%20or%20the%20Disk%20Management%20GUI. "Share on Pinterest")[Email](<mailto:?subject=How%20To%20Connect%20A%20EBS%20Volume%20To%20An%20Windows%20EC2%20Instance%20Using%20Powershell%2FGUI&body=Check out this article: https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-connect-a-ebs-volume-to-an-windows-ec2-instance-using-powershell-gui>)

## Comments

## You might also enjoy

More posts on similar topics

[![How to Connect to AWS RDS MySQL Database to EC2 Instance With PHP By Using PDO](/_astro/hero.BbyjrsxP_xhG8d.webp)](/blog/post/how-to-connect-to-aws-rds-mysql-database-to-ec2-instance-with-php-by-using-pdo)

## [How to Connect to AWS RDS MySQL Database to EC2 Instance With PHP By Using PDO](/blog/post/how-to-connect-to-aws-rds-mysql-database-to-ec2-instance-with-php-by-using-pdo)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [RDS](/blog/categories/rds)
-   [EC2](/blog/categories/ec2)
-   [PHP](/blog/categories/php)
-   [MySQL](/blog/categories/mysql)
-   [Database](/blog/categories/database)

Introduction In this post, we will learn how to connect an AWS RDS MySQL database to an EC2 instance with PHP, using PDO. PrerequisitesAWS Account EC2 Instance Amazon Linux 2 RDS MySQL

[#AWS RDS MySQL](/blog/tags/aws-rds-mysql)[#EC2 PHP PDO](/blog/tags/ec2-php-pdo)[#Database Connection](/blog/tags/database-connection)+5 tags

[read more](/blog/post/how-to-connect-to-aws-rds-mysql-database-to-ec2-instance-with-php-by-using-pdo)

[![How to Run an Apache Web Server Using Docker on an AWS EC2 Instance](/_astro/hero.WA3H4xsW_KuMrf.webp)](/blog/post/how-to-run-an-apache-web-server-using-docker-on-an-aws-ec2-instance)

## [How to Run an Apache Web Server Using Docker on an AWS EC2 Instance](/blog/post/how-to-run-an-apache-web-server-using-docker-on-an-aws-ec2-instance)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [EC2](/blog/categories/ec2)
-   [Docker](/blog/categories/docker)
-   [Apache](/blog/categories/apache)
-   [Web Server](/blog/categories/web-server)

Introduction In this post, we will learn how to run an Apache web server using Docker on an AWS EC2 instance. We will use the following tools:AWS EC2 \[Docker\](

[#AWS EC2 Docker](/blog/tags/aws-ec2-docker)[#Apache Docker](/blog/tags/apache-docker)[#Containerization](/blog/tags/containerization)+4 tags

[read more](/blog/post/how-to-run-an-apache-web-server-using-docker-on-an-aws-ec2-instance)

[![How to Install and Configure Node.js on EC2 Instance Amazon Linux 2](/_astro/hero.CIYv_zEL_2aFueX.webp)](/blog/post/how-to-install-and-configure-nodejs-on-ec2-instance-amazon-linux-2)

## [How to Install and Configure Node.js on EC2 Instance Amazon Linux 2](/blog/post/how-to-install-and-configure-nodejs-on-ec2-instance-amazon-linux-2)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [EC2](/blog/categories/ec2)
-   [Node.js](/blog/categories/nodejs)
-   [Linux](/blog/categories/linux)

Introduction Node.js does not exist in the default Amazon Linux 2 repository. So, we need to add the Node.js repository to the system. In this post, we will learn how to install and configure Node

[#Node.js Installation](/blog/tags/nodejs-installation)[#Amazon Linux 2](/blog/tags/amazon-linux-2)[#AWS EC2 Setup](/blog/tags/aws-ec2-setup)+3 tags

[read more](/blog/post/how-to-install-and-configure-nodejs-on-ec2-instance-amazon-linux-2)

[![How to Create a AWS RDS MySQL Database and Connect to it using MySQL Workbench](/_astro/hero.BalpSU3D_jRzSY.webp)](/blog/post/how-to-create-a-aws-rds-mysql-database-and-connect-to-it-using-mysql-workbench)

## [How to Create a AWS RDS MySQL Database and Connect to it using MySQL Workbench](/blog/post/how-to-create-a-aws-rds-mysql-database-and-connect-to-it-using-mysql-workbench)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [RDS](/blog/categories/rds)
-   [MySQL](/blog/categories/mysql)
-   [Database Management](/blog/categories/database-management)
-   [Cloud Computing](/blog/categories/cloud-computing)

Introduction RDS is a managed service that makes it easy to set up, operate, and scale a relational database in the cloud. It provides cost-efficient and resizable capacity while automating time-c

[#AWS RDS Setup](/blog/tags/aws-rds-setup)[#MySQL Workbench Connection](/blog/tags/mysql-workbench-connection)[#Relational Database](/blog/tags/relational-database)+4 tags

[read more](/blog/post/how-to-create-a-aws-rds-mysql-database-and-connect-to-it-using-mysql-workbench)

[![How To Connect A Two EC2 Instances Database and Files Transfer Using AWS CLI](/_astro/hero.839lq2GB_1XSap0.webp)](/blog/post/how-to-connect-a-two-ec2-instances-database-and-files-transfer-using-aws-cli)

## [How To Connect A Two EC2 Instances Database and Files Transfer Using AWS CLI](/blog/post/how-to-connect-a-two-ec2-instances-database-and-files-transfer-using-aws-cli)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [EC2](/blog/categories/ec2)
-   [EBS](/blog/categories/ebs)
-   [EFS](/blog/categories/efs)
-   [Database](/blog/categories/database)
-   [Networking](/blog/categories/networking)

Introduction In this post, I will show you how to share a database and files between two EC2 instances using AWS CLI. I will use AWS CLI to create a VPC, EC2 instances, EBS, EFS, and security grou

[#AWS CLI](/blog/tags/aws-cli)[#EC2 Instance Communication](/blog/tags/ec2-instance-communication)[#EBS Volume](/blog/tags/ebs-volume)+7 tags

[read more](/blog/post/how-to-connect-a-two-ec2-instances-database-and-files-transfer-using-aws-cli)

[![Scaling Up, Staying Strong: Hands-On AWS CloudFormation Techniques for Building Resilient and Scalable Systems](/_astro/hero.CoOFXLCa_Z2wwlfS.webp)](/blog/post/scaling-up-staying-strong-hands-on-aws-cloudformation-techniques-for-building-resilient-and-scalable-systems)

## [Scaling Up, Staying Strong: Hands-On AWS CloudFormation Techniques for Building Resilient and Scalable Systems](/blog/post/scaling-up-staying-strong-hands-on-aws-cloudformation-techniques-for-building-resilient-and-scalable-systems)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [Cloud Computing](/blog/categories/cloud-computing)
-   [DevOps](/blog/categories/devops)
-   [Infrastructure as Code](/blog/categories/infrastructure-as-code)
-   [Scalability](/blog/categories/scalability)
-   [Resilience](/blog/categories/resilience)

Introduction Building resilient and scalable systems matters for businesses that need to meet growing demand and maintain high availability. Cloud native architecture, combined with the capabiliti

[#AWS CloudFormation](/blog/tags/aws-cloudformation)[#IaC](/blog/tags/iac)[#Scalable Systems](/blog/tags/scalable-systems)+7 tags

[read more](/blog/post/scaling-up-staying-strong-hands-on-aws-cloudformation-techniques-for-building-resilient-and-scalable-systems)

6 related posts
