Find the New Drives connected through iSCSI

天大地大妈咪最大 提交于 2019-12-12 02:43:02

问题


I am writing a powerscript that connects to a target through ISCSi. I need to find the new drive letters (F:, G:, …) that is created after connecting. Is there any direct way to find that? MY script would be

New-IscsiTargetPortal -TargetPortalAddress $VirtualDeviceIp
Connect-IscsiTarget -NodeAddress $VirtualDeviceIQN
#Get the drives newly attached 

Though not straight I tried another way of doing it.

$initial=Get-Volume
New-IscsiTargetPortal -TargetPortalAddress $VirtualDeviceIp
Connect-IscsiTarget -NodeAddress $VirtualDeviceIQN
$final=Get-Volume
#Now compare $initial and $final to find the newly attached disks

But I dont know implement the second idea too :(


回答1:


Compare the DriveLetter property of the two sets:

Compare-Object $initial $final -Property 'DriveLetter'

Expanding the property will give you just the drive letter:

$driveLetter = Compare-Object $initial $final -Property 'DriveLetter' |
               select -Expand 'DriveLetter'

To be on the safe side you could add a filter that restricts results to "right side" items (i.e. newly added drives), thus excluding "left side" items (i.e. removed drives):

$driveLetter = Compare-Object $initial $final -Property 'DriveLetter' |
               ? { $_.SideIndicator -eq '=>' } |
               select -Expand 'DriveLetter'


来源:https://stackoverflow.com/questions/30957901/find-the-new-drives-connected-through-iscsi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!