Created
June 25, 2024 08:38
-
-
Save stknohg/28c20cab66319ef8ad3d7f923b5c5517 to your computer and use it in GitHub Desktop.
Windows EC2インスタンス内のドライブレターとEBSボリュームIDの紐づきを表示するコマンド
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-InstanceDrives () { | |
foreach ($disk in Get-Disk) { | |
# Get EBS volume ID | |
# * ref : https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-windows-volumes.html | |
$SerialNumber = $disk.SerialNumber | |
if ($SerialNumber -clike 'vol*') { | |
$EbsVolumeId = $SerialNumber.Substring(0, 20).Replace("vol", "vol-") | |
} else { | |
$EbsVolumeId = $SerialNumber.Substring(0, 20).Replace("AWS", "AWS-") | |
} | |
# Get partitions with Drive letter | |
foreach ($partion in (Get-Partition -DiskNumber $disk.Number -ErrorAction SilentlyContinue | Where-Object { $_.DriveLetter })) { | |
# Get volume | |
$volume = Get-Volume -DriveLetter $partion.DriveLetter | |
# Output results | |
[PSCustomObject]@{ | |
DiskNumber = $disk.Number | |
EBSVolumeId = $EbsVolumeId | |
FriendlyName = $disk.FriendlyName | |
PartitionNumber = $partion.PartitionNumber | |
DirveLetter = $partion.DriveLetter | |
FileSystem = $volume.FileSystem | |
FileSystemLabel = $volume.FileSystemLabel | |
Size = $volume.Size | |
SizeRemaining = $volume.SizeRemaining | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
実行例
単一EBSボリュームのWindows Server 2022 EC2インスタンスにSSM Session Managerで接続してコマンドを実行した場合。