VMware Cloud Community
IloveCoffee
Contributor
Contributor
Jump to solution

Adding SCSI(Tape, Enclosure) device to VM

Hi guys,

How can i add some scsi device to VM ?

The problem is when i have installed physical scsi controller i can't do any operation like vmotion.

And now i try make a script which will delete all specific controllers and all entities on it.

The problem is, i don't know how to add this tapes, enclosures to migrated vm.

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Get-ScsiLun -Hba (Get-VMHost -VM secret-01 | Get-VMHostHba -Type FibreChannel) -LunType tape, enclosu
re | Select-object CanonicalName, ConsoleDeviceName -unique
CanonicalName                                                                             ConsoleDeviceName
-------------                                                                             -----------------
naa.500143801600b946                                                                      /vmfs/devices/genscsi/naa.500143801600b946
naa.6a54908ad1680060030000000000c079                                                      /vmfs/devices/genscsi/naa.6a54908ad1680060030000000000c079
naa.500143801600b94c                                                                      /vmfs/devices/genscsi/naa.500143801600b94c
naa.6a54908ad1680060040000000000c079                                                      /vmfs/devices/genscsi/naa.6a54908ad1680060040000000000c079
naa.6a54908ad1680060010000000000c079                                                      /vmfs/devices/genscsi/naa.6a54908ad1680060010000000000c079
naa.6a54908ad1680060020000000000c079                                                      /vmfs/devices/genscsi/naa.6a54908ad1680060020000000000c079
naa.600c0ff000d78c110000000000000000                                                      /vmfs/devices/genscsi/naa.600c0ff000d78c110000000000000000
naa.600c0ff000d7700b0000000000000000                                                      /vmfs/devices/genscsi/naa.600c0ff000d7700b0000000000000000
naa.500143801600b943                                                                      /vmfs/devices/genscsi/naa.500143801600b943
naa.500143801600b949                                                                      /vmfs/devices/genscsi/naa.500143801600b949
PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>

i was trying adding like a disk, but not successfull.

Any ideas ?

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Can you run the following script against a VM where you manually connected the tape enclosure ?

I only want to see the results for the tape enclosure itself and for the SCSI controller to which it is connected.

$vmName = "MyVM"
$vm = Get-VM -Name $vmName

$vm
.ExtensionData.Config.Hardware.Device |
Select UnitNumber,Key,ScsiCtlrUnitNumber,ControllerKey,BusNumber,SharedBus,
  @{N="Label";E={$_.DeviceInfo.Label}},
  @{N="Summary";E={$_.DeviceInfo.Summary}},
  @{N="Type";E={$_.GetType().Name}},
 
@{N="Backing";E={$_.Backing.GetType().Name}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
17 Replies
IgorAfonin
Contributor
Contributor
Jump to solution

Oooh, wrong account for topic creation. I true owner of this topic.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Is that tape enclosure connected to an ESXi 5.x server ?

As per KB1016407, vSphere doesn't support directly attached tape drives to ESXi 5.x servers.

When you do the Get-ScsiLun do you see that tape SCSI device in there ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
IgorAfonin
Contributor
Contributor
Jump to solution

Hi Luc,

Yes i see the devices which directry attached to san.

In previous message i was showing thre result-listing of Get-ScsiLun.

I can do this manualy, but it's realy hard when you need to do this operation 20-40 times.

ESXi 5.0 (hp iso)

0 Kudos
LucD
Leadership
Leadership
Jump to solution

To make sure I got the question, when you do this manually you do:

  • "Edit Settings" on the  VM
  • On the Hardware tab you click "Add ..." and then you select SCSI Device
  • On "Choose SCSI Device" you select the tape enclosure


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
IgorAfonin
Contributor
Contributor
Jump to solution

yes, it's what i do when i using gui.

But now i want make a script for this stuff.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Can you run the following script against a VM where you manually connected the tape enclosure ?

I only want to see the results for the tape enclosure itself and for the SCSI controller to which it is connected.

$vmName = "MyVM"
$vm = Get-VM -Name $vmName

$vm
.ExtensionData.Config.Hardware.Device |
Select UnitNumber,Key,ScsiCtlrUnitNumber,ControllerKey,BusNumber,SharedBus,
  @{N="Label";E={$_.DeviceInfo.Label}},
  @{N="Summary";E={$_.DeviceInfo.Summary}},
  @{N="Type";E={$_.GetType().Name}},
 
@{N="Backing";E={$_.Backing.GetType().Name}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
IgorAfonin
Contributor
Contributor
Jump to solution

Here is your result

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> $vm.ExtensionData.Config.Hardware.Device |
>> Select UnitNumber,Key,ScsiCtlrUnitNumber,ControllerKey,BusNumber,SharedBus,
>>   @{N="Label";E={$_.DeviceInfo.Label}},
>>   @{N="Summary";E={$_.DeviceInfo.Summary}},
>>   @{N="Type";E={$_.GetType().Name}},
>>   @{N="Backing";E={$_.Backing.GetType().Name}} | Where{$_.label -match "SCSI"}
>>
UnitNumber         : 3 Key                : 1000 ScsiCtlrUnitNumber : 7 ControllerKey      : 100 BusNumber          : 0 SharedBus          : noSharing Label              : SCSI controller 0 Summary            : LSI Logic SAS Type               : VirtualLsiLogicSASController Backing            : UnitNumber         : 4 Key                : 1001 ScsiCtlrUnitNumber : 7 ControllerKey      : 100 BusNumber          : 1 SharedBus          : physicalSharing Label              : SCSI controller 1 Summary            : LSI Logic SAS Type               : VirtualLsiLogicSASController Backing            : UnitNumber         : 0 Key                : 2016 ScsiCtlrUnitNumber : ControllerKey      : 1001 BusNumber          : SharedBus          : Label              : SCSI device 1 Summary            : /vmfs/devices/genscsi/naa.500143801600b943 Type               : VirtualSCSIPassthrough Backing            : VirtualSCSIPassthroughDeviceBackingInfo UnitNumber         : 1 Key                : 2017 ScsiCtlrUnitNumber : ControllerKey      : 1001 BusNumber          : SharedBus          : Label              : SCSI device 2 Summary            : /vmfs/devices/genscsi/naa.500143801600b946 Type               : VirtualSCSIPassthrough Backing            : VirtualSCSIPassthroughDeviceBackingInfo UnitNumber         : 2 Key                : 2018 ScsiCtlrUnitNumber : ControllerKey      : 1001 BusNumber          : SharedBus          : Label              : SCSI device 3 Summary            : /vmfs/devices/genscsi/naa.500143801600b949 Type               : VirtualSCSIPassthrough Backing            : VirtualSCSIPassthroughDeviceBackingInfo UnitNumber         : 3 Key                : 2019 ScsiCtlrUnitNumber : ControllerKey      : 1001 BusNumber          : SharedBus          : Label              : SCSI device 4 Summary            : /vmfs/devices/genscsi/naa.6a54908ad1680060030000000000c079 Type               : VirtualSCSIPassthrough Backing            : VirtualSCSIPassthroughDeviceBackingInfo UnitNumber         : 4 Key                : 2020 ScsiCtlrUnitNumber : ControllerKey      : 1001 BusNumber          : SharedBus          : Label              : SCSI device 5 Summary            : /vmfs/devices/genscsi/naa.500143801600b94c Type               : VirtualSCSIPassthrough Backing            : VirtualSCSIPassthroughDeviceBackingInfo UnitNumber         : 5 Key                : 2021 ScsiCtlrUnitNumber : ControllerKey      : 1001 BusNumber          : SharedBus          : Label              : SCSI device 6 Summary            : /vmfs/devices/genscsi/naa.600c0ff000d78c110000000000000000 Type               : VirtualSCSIPassthrough Backing            : VirtualSCSIPassthroughDeviceBackingInfo UnitNumber         : 6 Key                : 2022 ScsiCtlrUnitNumber : ControllerKey      : 1001 BusNumber          : SharedBus          : Label              : SCSI device 7 Summary            : /vmfs/devices/genscsi/naa.6a54908ad1680060040000000000c079 Type               : VirtualSCSIPassthrough Backing            : VirtualSCSIPassthroughDeviceBackingInfo UnitNumber         : 8 Key                : 2024 ScsiCtlrUnitNumber : ControllerKey      : 1001 BusNumber          : SharedBus          : Label              : SCSI device 8 Summary            : /vmfs/devices/genscsi/naa.6a54908ad1680060000000000000c079 Type               : VirtualSCSIPassthrough Backing            : VirtualSCSIPassthroughDeviceBackingInfo UnitNumber         : 9 Key                : 2025 ScsiCtlrUnitNumber : ControllerKey      : 1001 BusNumber          : SharedBus          : Label              : SCSI device 9 Summary            : /vmfs/devices/genscsi/naa.6a54908ad1680060010000000000c079 Type               : VirtualSCSIPassthrough Backing            : VirtualSCSIPassthroughDeviceBackingInfo UnitNumber         : 10 Key                : 2026 ScsiCtlrUnitNumber : ControllerKey      : 1001 BusNumber          : SharedBus          : Label              : SCSI device 10 Summary            : /vmfs/devices/genscsi/naa.600c0ff000d7700b0000000000000000 Type               : VirtualSCSIPassthrough Backing            : VirtualSCSIPassthroughDeviceBackingInfo UnitNumber         : 11 Key                : 2027 ScsiCtlrUnitNumber : ControllerKey      : 1001 BusNumber          : SharedBus          : Label              : SCSI device 11 Summary            : /vmfs/devices/genscsi/naa.6a54908ad1680060020000000000c079 Type               : VirtualSCSIPassthrough Backing            : VirtualSCSIPassthroughDeviceBackingInfo

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try the following script.

Note: I'm afraid I couldn't fully test the script since I don't have any tape enclosures in my test environment.

function New-ScsiGenericDevice {
  param($VM,[string[]]$Device)

  $spec = New-Object VMware.Vim.VirtualMachineConfigSpec  

 
$devspec = New-Object VMware.Vim.VirtualDeviceConfigSpec
 
$devspec.operation = "add"
 
$controller = New-Object VMware.Vim.VirtualLsiLogicSASController
 
$controller.busNumber = 1
  $controller.key = -100
 
$controller.sharedBus = "physicalSharing"
 
$devspec.device = $controller
  $spec.DeviceChange += $devspec
 
$key = -1
 
$devunitnr = 0
 
$Device | %{     $devspec = New-Object VMware.Vim.VirtualDeviceConfigSpec
    $devspec.operation = "add"
    $unit = New-Object VMware.Vim.VirtualSCSIPassthrough
    $unit.backing = New-Object VMware.Vim.VirtualSCSIPassthroughDeviceBackingInfo
    $unit.backing.deviceName = "/vmfs/devices/genscsi/" + $_
   
$unit.Key = $key
   
$unit.UnitNumber = $devunitnr
   
$unit.controllerKey = -100
   
$devspec.device = $unit
   
$spec.DeviceChange += $devspec
   
$key--
   
if(++$devunitnr -eq 7){$devunitnr++}   }     $vm.ExtensionData.ReconfigVM_Task($spec) } $vmName = "MyVM" $vm = Get-VM -Name $vmName $tapes = Get-ScsiLun -Hba (Get-VMHost -VM $vm | Get-VMHostHba -Type FibreChannel) -LunType tape,enclosure | Select-object -ExpandProperty CanonicalName
New-ScsiGenericDevice
-VM $vm -Device $tapes


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

IgorAfonin
Contributor
Contributor
Jump to solution

Some errors on scsi 1:7, wich is reserved:

"Unable to configure virtual device scsi1:7 whose type is scsi-passthru. This virtual device is assigned a SCSI ID which is reserved for the virtual SCSI adapter. Move the virtual device to an unused SCSI ID and try again."

Sorry for long answer, trying solving the issue.

0 Kudos
IgorAfonin
Contributor
Contributor
Jump to solution

i can't resolving the problem Smiley Sad

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I made some changes to the script above, and it should now skip unitnumber 7.

Can you try again ?

Note that there are other potential problems, if there are more than 15 generic devices, the script script should go to a new SCSI controller.

That is not included in the current version


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

IgorAfonin
Contributor
Contributor
Jump to solution

Yeah, it works!

I wasted alot of time with $unit.Key, i dont knows about $unit.UnitNumber. Smiley Happy

Great thanks, with controllers i will make changes and will write block for automaticly adding new controller.

0 Kudos
IloveCoffee
Contributor
Contributor
Jump to solution

Luc, hi

I have a question (or problem), i was trying write a block with adding additional scsi controller and all my task results it's:

A specified parameter was not correct.


The Code:

function New-ScsiGenericDevice {
param($VM,[string[]]$Device)
    $global:spec = New-Object VMware.Vim.VirtualMachineConfigSpec 

    $global:ctrkey = -99
    $key = -1
    $devunitnr = 10
    $global:busnumber = 0
    #$global:devctrkey = -99

    function New-ScsiContrller {
        $global:busnumber++
        $global:ctrkey--
        $global:devctrkey--
        $devspec = New-Object VMware.Vim.VirtualDeviceConfigSpec
        $devspec.operation = "add"
        $controller = New-Object VMware.Vim.VirtualLsiLogicSASController
        $controller.busNumber = $global:busnumber
        $controller.key = $global:ctrkey
        #$controller.ControllerKey = $global:devctrkey
        $controller.sharedBus = "physicalSharing"
        $devspec.device = $controller
        $global:spec.DeviceChange += $devspec
        #$controller
    }

    New-ScsiController
    $Device | %{
        $devspec = New-Object VMware.Vim.VirtualDeviceConfigSpec
        $devspec.operation = "add"
        $unit = New-Object VMware.Vim.VirtualSCSIPassthrough
        $unit.backing = New-Object VMware.Vim.VirtualSCSIPassthroughDeviceBackingInfo
        $unit.backing.deviceName = "/vmfs/devices/genscsi/" + $_
        $unit.Key = $key
        $unit.UnitNumber = $devunitnr
        $unit.controllerKey = $global:ctrkey
        $devspec.device = $unit
        $global:spec.DeviceChange += $devspec
        $key--
        if(++$devunitnr -eq 7){$devunitnr++}
        if  ($devunitnr -eq 14) {New-ScsiController #if number of units eq 15, then add new controller
                                $devunitnr = 0
                                $key = -1}
        #$unit
      }

  $vm.ExtensionData.ReconfigVM_Task($global:spec)
}

$vmName = "tenrck-secret-01"
$vm = Get-VM -Name $vmName
$tapes = Get-ScsiLun -Hba (Get-VMHost -VM $vm | Get-VMHostHba -Type FibreChannel) -LunType tape,enclosure | Select-object -ExpandProperty CanonicalName

New-ScsiGenericDevice -VM $vm -Device $tapes

I add in code output of objects like:

    for ($i = 0;$i -le $global:spec.DeviceChange.Count;$i++)
    {
        if ($global:spec.DeviceChange[$i].Device -ne $null){
            $global:spec.DeviceChange[$i].Device.GetType().Name            
         if
($global:spec.DeviceChange[$i].Device.GetType().Name -eq "VirtualLsiLogicSASController"){              Write-Host "Object #" $i               
             Write-Host
"BusNumber :" $global:spec.DeviceChange[$i].Device.BusNumber               
            
Write-Host "Key :" $global:spec.DeviceChange[$i].Device.Key               
            
Write-Host "SharedBus :" $global:spec.DeviceChange[$i].Device.SharedBus           
         }        
elseif ($global:spec.DeviceChange[$i].Device.GetType().Name -eq "VirtualSCSIPassthrough"){              Write-Host "Object #" $i               
             Write-Host
"DeviceKey :" $global:spec.DeviceChange[$i].Device.Key               
            
Write-Host "ControllerKey :" $global:spec.DeviceChange[$i].Device.ControllerKey               
            
Write-Host "UnitNumber :" $global:spec.DeviceChange[$i].Device.UnitNumber               
            
Write-Host "DeviceName :" $global:spec.DeviceChange[$i].Device.Backing.DeviceName           
         }         }     }

The output:

PS C:\Users\Igor.Afonin> & 'C:\Users\IGOR~1.AFO\AppData\Local\Temp\Untitled20.ps1'
VirtualLsiLogicSASController
Object # 0
BusNumber : 1
Key : -100
SharedBus : physicalSharing

VirtualSCSIPassthrough
Object # 1
DeviceKey : -1
ControllerKey : -100
UnitNumber : 10
DeviceName : /vmfs/devices/genscsi/naa.500143801600b946

VirtualSCSIPassthrough
Object # 2
DeviceKey : -2
ControllerKey : -100
UnitNumber : 11
DeviceName : /vmfs/devices/genscsi/naa.6a54908ad1680060030000000000c079

VirtualSCSIPassthrough
Object # 3
DeviceKey : -3
ControllerKey : -100
UnitNumber : 12
DeviceName : /vmfs/devices/genscsi/naa.500143801600b94c

VirtualSCSIPassthrough
Object # 4
DeviceKey : -4
ControllerKey : -100
UnitNumber : 13
DeviceName : /vmfs/devices/genscsi/naa.6a54908ad1680060040000000000c079

VirtualLsiLogicSASController
Object # 5
BusNumber : 2
Key : -101
SharedBus : physicalSharing

VirtualSCSIPassthrough
Object # 6
DeviceKey : -1
ControllerKey : -101
UnitNumber : 0
DeviceName : /vmfs/devices/genscsi/naa.6a54908ad1680060010000000000c079

VirtualSCSIPassthrough
Object # 7
DeviceKey : -2
ControllerKey : -101
UnitNumber : 1
DeviceName : /vmfs/devices/genscsi/naa.6a54908ad1680060020000000000c079

VirtualSCSIPassthrough
Object # 8
DeviceKey : -3
ControllerKey : -101
UnitNumber : 2
DeviceName : /vmfs/devices/genscsi/naa.600c0ff000d78c110000000000000000

VirtualSCSIPassthrough
Object # 9
DeviceKey : -4
ControllerKey : -101
UnitNumber : 3
DeviceName : /vmfs/devices/genscsi/naa.600c0ff000d7700b0000000000000000

VirtualSCSIPassthrough
Object # 10
DeviceKey : -5
ControllerKey : -101
UnitNumber : 4
DeviceName : /vmfs/devices/genscsi/naa.500143801600b943

VirtualSCSIPassthrough
Object # 11
DeviceKey : -6
ControllerKey : -101
UnitNumber : 5
DeviceName : /vmfs/devices/genscsi/naa.500143801600b949

In results i have 2 controllers -100 and -101, and all devices was mapping on it.

Can you help me ?

And another little question, which syntax highlite you are using ?

PS: I am newbie in powershell programming.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Would you mind attaching the script you are currently using as a file ?

I'm not sure I'm seeing the correct version in your last post.

To highlight code see Some ways to enter PowerCLI code under the new forum SW


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
IgorAfonin
Contributor
Contributor
Jump to solution

Luc, ps1 file in attachement.

file run log:

PS C:\Users\Igor.Afonin> & 'D:\scripts\pshell\New-ScsiGenericDrive.ps1'
VirtualLsiLogicSASController
Object # 0
BusNumber : 1
Key : -100
SharedBus : physicalSharing
VirtualSCSIPassthrough
Object # 1
DeviceKey : -1
ControllerKey : -100
UnitNumber : 10
DeviceName : /vmfs/devices/genscsi/naa.500143801600b946
VirtualSCSIPassthrough
Object # 2
DeviceKey : -2
ControllerKey : -100
UnitNumber : 11
DeviceName : /vmfs/devices/genscsi/naa.6a54908ad1680060030000000000c079
VirtualSCSIPassthrough
Object # 3
DeviceKey : -3
ControllerKey : -100
UnitNumber : 12
DeviceName : /vmfs/devices/genscsi/naa.500143801600b94c
VirtualSCSIPassthrough
Object # 4
DeviceKey : -4
ControllerKey : -100
UnitNumber : 13
DeviceName : /vmfs/devices/genscsi/naa.6a54908ad1680060040000000000c079
VirtualLsiLogicSASController
Object # 5
BusNumber : 2
Key : -101
SharedBus : physicalSharing
VirtualSCSIPassthrough
Object # 6
DeviceKey : -1
ControllerKey : -101
UnitNumber : 0
DeviceName : /vmfs/devices/genscsi/naa.6a54908ad1680060010000000000c079
VirtualSCSIPassthrough
Object # 7
DeviceKey : -2
ControllerKey : -101
UnitNumber : 1
DeviceName : /vmfs/devices/genscsi/naa.6a54908ad1680060020000000000c079
VirtualSCSIPassthrough
Object # 8
DeviceKey : -3
ControllerKey : -101
UnitNumber : 2
DeviceName : /vmfs/devices/genscsi/naa.600c0ff000d78c110000000000000000
VirtualSCSIPassthrough
Object # 9
DeviceKey : -4
ControllerKey : -101
UnitNumber : 3
DeviceName : /vmfs/devices/genscsi/naa.600c0ff000d7700b0000000000000000
VirtualSCSIPassthrough
Object # 10
DeviceKey : -5
ControllerKey : -101
UnitNumber : 4
DeviceName : /vmfs/devices/genscsi/naa.500143801600b943
VirtualSCSIPassthrough
Object # 11
DeviceKey : -6
ControllerKey : -101
UnitNumber : 5
DeviceName : /vmfs/devices/genscsi/naa.500143801600b949
Type                                                           Value
----                                                           -----
Task                                                           task-18549
PS C:\Users\Igor.Afonin>

0 Kudos
IgorAfonin
Contributor
Contributor
Jump to solution

Luc, Sorry for disturbing.

Scritp working perfectly, my mistake was because i already have controller 1:x.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

No problem, glad you got it working.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos