How to Get LUN ID and Mount New RAW LUN in a Folder - Windows Server 2016

Slight update from the previous post. Here we are playing with LUN ID 99:

"rescan" | diskpart
[System.Object]$Disk
[System.Object]$Disk = @{}
[System.Object]$Disk."LUN_N1_99" = Get-Disk -Number (Get-WmiObject Win32_DiskDrive | where{ $_.scsilogicalunit -eq 99 }).Index
$Disk."LUN_N1_99"
$Disk."LUN_N1_99" | Set-Disk -IsOffline $false
$Disk."LUN_N1_99" | Initialize-Disk -PartitionStyle GPT
$Disk."LUN_N1_99" | New-Partition -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel "LUN_N1_99"
New-Item -Path C:\LUN099 -ItemType Directory
Get-Volume | Where{$_.FileSystemLabel -eq "LUN_N1_99"} | Get-Partition | Add-PartitionAccessPath -AccessPath "C:\LUN099"

Image: LUN Mapping Example

Comments