0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SANsymphonyをデータストアとして使っているvSphere環境で全ESXiの全データストアにパスを一括追加するパワーシェルスクリプト

Posted at

とあるユーザーの作業で使うために作ったのでここに共有しておきます。

条件

  1. Register VMware vCenterを使っていること
  2. iSCSI接続
  3. 各ESXiは既にVMFSデータストアとしてマウントしている (新規じゃない)

実行するとどうなるか

既存のデータストアに同一LUNでパスを足してくれます。

中身

まずPowerCLIでターゲットIPを追加します。

# vCenter Serverに接続
Connect-VIServer -Server x.x.x.x -User administrator@vsphere.local -Password xxxxxxxx

# 全ESXiにターゲットIPアドレスを追加するコマンド(4IPなら4行書けばOK)
Get-vmhost | get-vmhosthba -type iscsi | New-IScsiHbaTarget -Address "w.w.w.w"
Get-vmhost | get-vmhosthba -type iscsi | New-IScsiHbaTarget -Address "x.x.x.x"
Get-vmhost | get-vmhosthba -type iscsi | New-IScsiHbaTarget -Address "y.y.y.y"
Get-vmhost | get-vmhosthba -type iscsi | New-IScsiHbaTarget -Address "z.z.z.z"

# 全ESXiでリスキャン
Get-VMHost | Get-VMHostStorage -RescanAllHBA

# vCenterから切断
Disconnect-VIServer -Confirm:$False

その次のデータコアサーバー側で各vDiskにパスを追加していきます。

Import-Module 'C:\Program Files\DataCore\SANsymphony\DataCore.Executive.Cmdlets.dll' -WarningAction silentlyContinue

# 接続
Connect-DcsServer  -Server x.x.x.x -UserName administrator -Password xxxxxxxxx

# データコアサーバ一覧取得(名前でソート)
$SERVER = Get-DcsServer | Sort-Object HostName

# FEポート一覧取得(名前でソート)
$FE = @()
get-dcsport -Machine $Server[0] | Sort-Object Alias | foreach {
    if ($_.serverportproperties.role  -eq "Frontend"){
        $FE += $_
    }
}       

# vDisk一覧取得(名前でソート)
$VD = Get-DcsVirtualDisk | Sort-Object Alias

# ESXi一覧取得
$ESXI = Get-DcsClient|where-object { $_.Type -eq "ESX" }

# 1. vDiskごとにループさせる
foreach($VDstr in $VD){
    #下2行はコメントアウトしてもOK
    Write-Host($VDstr.Caption + " に追加します")
    Read-Host "続けるにはENTERキーを押して下さい" 
    $LD = $VDstr | Get-DcsLogicalDisk
    #2. クライアントごとにループさせる
    foreach($ESXIstr in $ESXI){
        $ESXIPORT = Get-DcsPort -Machine $ESXIstr | Where-Object{$_.PortType  -like "iSCSI"}
        #既存LUNを取得する(VMwareは同一データストアは同一番号の必要があるため)
        $LUN = $VDstr | Get-DcsVirtualLogicalUnit -InitiatorHost $ESXIstr |Select-Object lun
        #3. 2データコアサーバー分ループ
        foreach($SERVERstr in $SERVER){
            #4. 全FEパス分ループ
            foreach($FEstr in $FE){
                #5. FEパス追加
                #LDどっちを使うか判断(ミラーなので内部的に2つディスクデバイスがある)
                if($LD[0].Caption -match $SERVERstr.HostName){
                    $LDstr = $LD[0]
                }else{
                    $LDstr = $LD[1]
                }
                Add-DcsVirtualLogicalUnit -InitiatorHost $ESXIstr -TargetHost $SERVERstr.RegionNodeId -InitiatorPort $ESXIPORT -TargetPort $FEstr -LogicalDisk $LDstr  -MappingType Client -LUN $LUN[0].lun
                }
            }
        }
    }
Disconnect-DcsServer

最後に全台リスキャンしてもいいかも。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?