Hi All,
I am using the below script to obtain LUN ID and Disk letter.`
function Get-DiskScsiLun {
[CmdletBinding()]
param([Parameter(Mandatory = $false,
Position = 0)]
[alias("Disk")]
[string] $DeviceID = '*',
[Parameter(Mandatory = $false,
Position = 1,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)]
[alias("CN")]
[String[]] $ComputerName = $env:COMPUTERNAME,
[Parameter(Mandatory=$false,
Position = 2)]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()] $Credential = [System.Management.Automation.PSCredential]::Empty
)
process {
if ($ComputerName)
{
# Loop through all computers in the parameter list
foreach ($Computer in $ComputerName) {
try {
if ($Computer -eq "$($env:COMPUTERNAME)" -or $Computer -eq "." -or $Computer -eq "localhost")
{
# Define the Get-WmiObject parameter set for the local computer
$Parameters = @{
Impersonation = 3
ErrorAction = 'Stop'
}
}
else
{
# Define the Get-WmiObject parameter set for remote computers
$Parameters = @{
ComputerName = $Computer
Credential = $Credential
ErrorAction = 'Stop'
}
}
# Test if the computer can be connected
if (Test-Connection -ComputerName $Computer -Count 1 -Quiet)
{
# Get the WMI objects
$Win32_LogicalDisk = Get-WmiObject -Class Win32_LogicalDisk @Parameters |
Where-Object {$_.DeviceID -like $DeviceID}
$Win32_LogicalDiskToPartition = Get-WmiObject -Class Win32_LogicalDiskToPartition @Parameters
$Win32_DiskDriveToDiskPartition = Get-WmiObject -Class Win32_DiskDriveToDiskPartition @Parameters
$Win32_DiskDrive = Get-WmiObject -Class Win32_DiskDrive @Parameters
# Search the SCSI Lun Unit for the disk
$Win32_LogicalDisk |
ForEach-Object {
if ($_)
{
$LogicalDisk = $_
$LogicalDiskToPartition = $Win32_LogicalDiskToPartition |
Where-Object {$_.Dependent -eq $LogicalDisk.Path}
if ($LogicalDiskToPartition)
{
$DiskDriveToDiskPartition = $Win32_DiskDriveToDiskPartition |
Where-Object {$_.Dependent -eq $LogicalDiskToPartition.Antecedent}
if ($DiskDriveToDiskPartition)
{
$DiskDrive = $Win32_DiskDrive |
Where-Object {$_.__Path -eq $DiskDriveToDiskPartition.Antecedent}
if ($DiskDrive)
{
# Return the results
New-Object -TypeName PSObject -Property @{
Computer = $Computer
DeviceID = $LogicalDisk.DeviceID
SCSIBus = $DiskDrive.SCSIBus
SCSIPort = $DiskDrive.SCSIPort
SCSITargetId = $DiskDrive.SCSITargetId
SCSILogicalUnit = $DiskDrive.SCSILogicalUnit
Size=[Math]::Round($DiskDrive.size / 1GB, 2)
FreeSpace=[Math]::Round($LogicalDisk.FreeSpace / 1GB, 2)
}
}
}
}
}
}
}
else
{
Write-Warning "Unable to connect to computer $Computer."
}
}
catch {
Write-Warning "Unable to get disk information for computer $Computer.`n$($_.Exception.Message)"
}
}
}
}
}`
My output will come in below format.
How do i obtain the results in below format..I think its called transpose.
Thanks,
ACDBA