Powercli批量添加iscsi软适配器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Powercli批量添加iscsi软适配器相关的知识,希望对你有一定的参考价值。

1、第一步,开启软件iscsi适配器

Get-VMHostStorage -VMHost 172.16.15.* | Set-VMHostStorage -SoftwareIScsiEnabled $true

#将所有172.16.15.X开头的esxi主机的iscsi软件适配器打开


2、第二步,配置iscsi服务器地址

$hba = $GETHOST | Get-VMHostHba -type IScsi  | ?{$_.Model -like "*iSCSI Software*"}

$target = "172.16.15.173"

New-IScsiHbaTarget -IScsiHba $hba -Address $target -WarningAction SilentlyContinue | Out-Null

#把以上代码保存为ps1文件执行即可。

#172.16.15.173为iscsi目标服务器地址


=====================================================================================


以下是另一个小脚本,只需要把想修改的esxi地址填进去就可以了

#FQDNs or IP addresses of ESXi Hosts to Configure

#Enclose each host in quotes and separate with a comma.

#此处输入要修改的esxi主机地址,Example: $ESXiHosts = "192.168.1.1","192.168.1.2"

$ESXiHosts = "172.16.15.131", "172.16.15.132"

# Prompt for ESXi Root Credentials

$esxcred = Get-Credential 

#Connect to each host defined in $ESXiHosts

Connect-viserver -Server $ESXiHosts -Credential $esxcred

# Set $targets to the SendTargets you want to add. Enclose each target in quotes and separate with a comma.

# 此处输入iscsi目标服务器地址,可以是多个地址,Example: $targets = "192.168.151.10", "192.168.151.11", "192.168.151.12", "192.168.151.13"

$targets = "172.16.15.173"

foreach ($esx in $ESXiHosts) {

# Enable Software iSCSI Adapter on each host

  Write-Host "Enabling Software iSCSI Adapter on $esx ..."

  Get-VMHostStorage -VMHost $esx | Set-VMHostStorage -SoftwareIScsiEnabled $True

# Just a sleep to wait for the adapter to load

  Write-Host "Sleeping for 5 Seconds..." -ForegroundColor Green

  Start-Sleep -Seconds 5

  Write-Host "OK Here we go..." -ForegroundColor Green

  Write-Host "Adding iSCSI SendTargets..." -ForegroundColor Green

  $hba = Get-VMHost | Get-VMHostHba -Type iScsi | ?{$_.Model -like "*iSCSI Software*"}

  foreach ($target in $targets) {

# Check to see if the SendTarget exist, if not add it

  if (Get-IScsiHbaTarget -IScsiHba $hba -Type Send | Where {$_.Address -cmatch $target}) 

  { Write-Host "The target $target does exist on $esx" -ForegroundColor Green }

   else {

        Write-Host "The target $target doesn‘t exist on $esx" -ForegroundColor Red

        Write-Host "Creating $target on $esx ..." -ForegroundColor Yellow

        New-IScsiHbaTarget -IScsiHba $hba -Address $target       

     }

  }

}

Write "`n Done - Disconnecting from $ESXiHosts"

Disconnect-VIServer -Server * -Force -Confirm:$false

Write-Host "Done! Now go manually add the iSCSI vmk bindings to the Software iSCSI Adapter and Resan." -ForegroundColor Green


本文出自 “我还活着呢” 博客,请务必保留此出处http://hujizhou.blog.51cto.com/514907/1969498

以上是关于Powercli批量添加iscsi软适配器的主要内容,如果未能解决你的问题,请参考以下文章

Powercli 批量添加vmkernel网络

PowerCLi 批量添加所有esxi到vCenter

PowerCLI脚本批量和一些常用自动化操作脚本

PowerCLi 通过vCenter批量创建及管理虚拟交换机到所有esxi主机

PowerCLi 管理VMware vCenter 一键批量部署OVA

PowerCLi 管理VMware vCenter 批量部署导出导入