Powercli批量添加iscsi软适配器

简介:

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

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

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


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

1
2
3
$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地址填进去就可以了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#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









本文转自 qq8658868 51CTO博客,原文链接:http://blog.51cto.com/hujizhou/1969498,如需转载请自行联系原作者
目录
相关文章
|
5月前
|
Ubuntu KVM 虚拟化
利用ESXi学习设备vfio设备直通
利用ESXi学习设备vfio设备直通
|
9月前
|
虚拟化 数据安全/隐私保护 网络架构
在ESXi上搭建自己的OpenWRT软路由系统
在ESXi上搭建自己的OpenWRT软路由系统
在ESXi上搭建自己的OpenWRT软路由系统
|
存储 缓存 Linux
rhel7 iscsi服务,多路径聚合,权限更改
rhel7 iscsi服务,多路径聚合,权限更改
570 0
|
虚拟化 Windows
记一次被动的网卡升级:VMWare导致的无线网卡不能启用
最近在下潜心研究持续集成的环境搭建、折腾VMWare虚拟机比较频繁。上周的某一天笔记本的无线网卡突然罢工了;重装驱动也完全没有作用。 网上的攻略都是重装网卡驱动,对于问题的定位和我遇到的根本对不上;当然不能期望过高,大部分时候重装驱动就能解决。
2761 0
|
网络安全 虚拟化 Windows
关于win10系统安装VMware12Pro后,win10系统的 控制面板\网络和 Internet\网络连接\更改适配器选项卡中 没有虚拟网卡VMnet1和VMnet8图标,该如何把他们显示出来呢?
安装VMware12Pro后,PC主机通过命令行:ipconfig/all ,查看发现没有 VMnet1 和VMnet8 。 然后我首先尝试打开VMware12Pro的虚拟网络编辑器; 然后先点击“更改设置”按钮,获得权限,再点击还原默认设置;(下图是已经连接好的啊!!!)   经过一段时间的等待...
2242 0
Win10没有以太网图标如何找回?以太网适配器不见了怎么恢复?
Win10以太网适配器不见了怎么恢复?以太网其实就是Win7系统中常说的“本地连接”假若用户发现网络适配器中的以太网适配器图标不见了,可以在设备管理器中添加一些这类适配器,具体过程请看下文。   Win10以太网适配器不见了怎么恢复?   1、在开始菜单上右键,打开“设备管理器”。
1724 0