Chinaunix首页 | 论坛 | 博客
  • 博客访问: 152620
  • 博文数量: 30
  • 博客积分: 30
  • 博客等级: 民兵
  • 技术积分: 310
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-31 15:35
文章分类

全部博文(30)

文章存档

2020年(1)

2019年(10)

2016年(19)

我的朋友

分类: 系统运维

2019-10-14 08:40:43

sz080365:mwadmin@/powerclidata/data>cat ../bin/esxwwnreport.ps1 
function getesxwwn($serverip){
$RESULTFILE="/powerclidata/data/ESXHOSTWWNINFO_"+$serverip+"_$(Get-Date -Format 'yyyyMMdd').txt"
$INFO=Get-VMHost
$Title="vcip esxip esxhn device speed wwn status"
$RESULT=Foreach ($esxip in $INFO) {
$ESXHOSTINFO=$esxip |Get-View
$IPADDR=$esxip.Name
$esxntinfo=Get-VMHostNetwork -VMHost $esxip
$ESXHNAME=$esxntinfo.HostName
$ESXVCHNAME=$serverip
$HBAINFO=$ESXHOSTINFO.config.StorageDevice.HostBusAdapter
foreach ($i in $HBAINFO){
  $device=$i.Device  
  $speed=$i.Speed
  $status=$i.Status
  $wwn=('{0:X}' -f ($i.PortWorldWideName))
  if ($status -eq "online"){
  $aa="";$x='';$y='';$count=0;$wwn -split ""|foreach{if($_ -ne ""){$_}}|foreach{$count+=1;if($count%2 -eq 1){$x=$_};if($count%2 -eq 0){$y=$_;-join ($x,$y)}} |foreach{$aa=-join($aa,":",$_)}
  $wwn=$aa.Substring(1,23) 
  $ESXVCHNAME +" "+ $IPADDR+" "+  $ESXHNAME+" "+  $device+" "+  $speed+" "+  $wwn+" "+  $status
  }
}
}
$Title|format-table -AutoSize |Out-File $RESULTFILE -Width 512
$RESULT|format-table -AutoSize |Out-File -Append $RESULTFILE -Width 512
}


function run(){
$serverip=$global:DefaultVIServer.name
If($serverip){Disconnect-VIServer -Server $serverip -Force -Confirm:$false}
$vclist=Get-Content /powerclidata/bin/vclist.txt
$vclist|foreach{
  $serverip=$_
  $Server=Connect-VIServer -Server $serverip -Protocol https -User 'xxx' -Password 'xxx'
  getesxwwn($serverip)
  Disconnect-VIServer -Server  $Server -Force -Confirm:$false
}
}


############ main #########
Import-Module PowerCLI.Cis
Import-Module PowerCLI.Vds
Import-Module PowerCLI.ViCore
set-PowerCLIConfiguration -invalidCertificateAction "ignore" -confirm:$false
run

sz080365:mwadmin@/powerclidata/data>powershell -File ../bin/esxwwnreport.ps1 
sz080365:mwadmin@/powerclidata/data>cat ESXHOSTWWNINFO_10.60.100.179_20191014.txt 
ip esxip esxhn device speed wwn status
10.60.100.179 10.60.100.172 sz150027 vmhba3 8 21:00:34:80:0D:6B:9B:3D online
10.60.100.179 10.60.100.172 sz150027 vmhba6 8 21:00:34:80:0D:6B:9B:37 online
10.60.100.179 10.60.100.178 sz150033 vmhba3 8 21:00:34:80:0D:6B:9E:23 online
10.60.100.179 10.60.100.178 sz150033 vmhba6 8 21:00:34:80:0D:6B:9A:01 online
...略...
sz080365:mwadmin@/powerclidata/data>

阅读(5861) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~